You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Rune Sandnes <ru...@klapp.no> on 2002/04/14 12:32:28 UTC

Destroying cached object

I have looked at various methods of deciding when a cached object is no
longer 
valid (including DBPrism cache invalidator suggested by Marcelo Ochoa)

What I really want to do is simple, cache all pages for 30 minutes with 
DeltaTimeCacheValidity, but be able to destroy the cache from the
Content
Management System. When working with documents in the CMS they are
called
with a nocache parameter, and Cocoon serves them uncached.

     public CacheValidity generateValidity() {
        // If we are called with nocache parameter we do not cache
	  if ( request.getParameter("nocache") == null ) {
	     return new DeltaTimeCacheValidity(30);
	  } else {
	     return null;
	  }
     }

What I was hoping for was that when CacheValidity returns null, it will
destroy the cached object for good, but that doesn't seem to happen. The

next time the document is called from the site without the nocache
parameter,
I get the old version (for the duration of the 30 minute cache period).

So, is there any way I can instruct Cocoon to destroy a particular
cached
object permanently?

Cocoon 2.0.2, Tomcat 4.0.3

Thanks,
Rune,
Trondheim,
Norway

---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>


RE: Destroying cached object

Posted by Vadim Gritsenko <va...@verizon.net>.
> From: Rune Sandnes [mailto:rune@klapp.no]
> 
> 
> I have looked at various methods of deciding when a cached object is
no
> longer
> valid (including DBPrism cache invalidator suggested by Marcelo Ochoa)
> 
> What I really want to do is simple, cache all pages for 30 minutes
with
> DeltaTimeCacheValidity, but be able to destroy the cache from the
> Content
> Management System. When working with documents in the CMS they are
> called
> with a nocache parameter, and Cocoon serves them uncached.
> 
>      public CacheValidity generateValidity() {
>         // If we are called with nocache parameter we do not cache
> 	  if ( request.getParameter("nocache") == null ) {
> 	     return new DeltaTimeCacheValidity(30);
> 	  } else {
> 	     return null;
> 	  }
>      }
> 
> What I was hoping for was that when CacheValidity returns null, it
will
> destroy the cached object for good, but that doesn't seem to happen.
The
> 
> next time the document is called from the site without the nocache
> parameter,
> I get the old version (for the duration of the 30 minute cache
period).
> 
> So, is there any way I can instruct Cocoon to destroy a particular
> cached object permanently?

You need to return such a ValidityObject (serializable), which will
return "false" when your XSP need it. To clarify this moment, here is
simple example:

---------------------
class MyCacheValidity extends DeltaTimeCacheValidity {
  boolean cache;

  public MyCacheValidity (int minutes, boolean cache) {
    super(minutes);
    this.cache = cache;
  }

  public boolean isValid(CacheValidity validity) {
    // check "cache" parameter from the XSP
    if (((MyCacheValidity)validity).cache)
      return false;
    // Check 30 min
    return super.isValid();
  }
}
---------------------
public CacheValidity generateValidity() {
  // If we are called with nocache parameter we do not cache
  if (request.getParameter("nocache") == null) {
    return new MyCacheValidity(30, false);
  } else {
    return new MyCacheValidity(30, true);
  }
}
---------------------

PS You should know that there are two validity objects for a given cache
key: One is in cache (generated by XSP and cached on previous request to
this XSP), and another is generated by your XSP to be compared with the
cached validity. Take a look at the TimeStampCacheValidity.java.

Vadim

 
> Cocoon 2.0.2, Tomcat 4.0.3
> 
> Thanks,
> Rune,
> Trondheim,
> Norway
> 


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>