Re: Two questions about cache

Jacob Smullyan <[email protected]>
Newsgroups gmane.comp.web.skunkweb
Message-ID <[email protected]>
On Sat, Apr 17, 2004 at 10:46:42AM +0000, Andreas Kaempf wrote:
> First of all, thanks and appreciation to Drew, Jacob and other
> contributors for developing and sharing such a superb piece of software.
> Coming from the opaque mysteries of Zope, I am finding the transparency,
> simplicity, and power of SkunkWeb refreshing. It really deserves to be
> better known.

That's nice to hear!  Thanks!
 
> I am developing a site that includes news articles with threaded
> comments, all pulled from a database, and was wondering whether there
> was a way of programmatically invalidating a page's cache. Basically,
> the cached version should be valid until we know a change has been made
> (i.e., an article has been added or a comment added). It would be nice
> to be able to say "this page has been changed, refresh anew next time
> requested" rather than relying on a time interval.

One approach to this problem is described here:

  http://wiki.skunkweb.org/sw/ClearingTheCache

I recently wrote a threaded discussion application, and I solved the
problem by passing to my "render_thread" component a
"thread_last_updated" argument, which was obtained fresh every
request.  Since any update to the thread changed the return value of
thread_last_updated.pydcmp, the cache for the rendering of that thread
was in effect invalidated.

Another approach would be to create a new cache entry rather than
simply invalidate it, with cache=DEFER or cache=FORCE, doing the work
up front rather than lazily.  That might involve the component getting
called repeatedly when it isn't needed, however; and if you have
several component calls that need to be invalidated, or a range of
them, it won't help.

The problem with the clearing the cache is that if you don't know the
exact arguments with which the component was called, you don't know
what the cache key would be, so you have to check the component
arguments of each cache entry one by one (and furthermore the cache
needs to be set up to store those arguments, which used to be the
default but in CVS now isn't, so that you don't have to pay that
penalty if you don't use the corresponding feature) and see if they
match.  In most cases, you can figure out another way of using the cache
that makes clearing it unnecessary.  

But if you really want to clear the cache, there is a clearCache
method in AE.Cache.  It won't work unless you set
Configuration.writeCacheFiles to a true value.  I'm not sure it works
even then, as I've never used it.  Report your experiences with it if
you dive into those dismal waters!

> My second question was whether it is safe to delete the contents of
> /usr/local/skunk/cache occasionally during development to force pages to
> be generated fresh, rather than from cache. I'm finding that components
> called from components are sometimes drawn from cache even if the source
> file has been changed.

Yes, you can do that.  BTW, you want to be careful about calling
components from the cache from components that are themselves called
from the cache!  Generally that doesn't do what you want.  

Cheers,

js
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAgTKjuqamFyFXXLIRAltGAKDJjfvIOu/9oXyAIrru5rl1DAbFbwCeJGrn
4I340moniUGpilyCFPAA7sA=
=RdMw
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.