lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Thu, Aug 20, 2009 at 11:32 AM, Lawrie Nichols<lawrien@gmail.com> wrote:
>> d) use the 'changed condition' as part of the key to your cache.
>
> Sorry, I don't understand what you're saying. Could you expand on this a
> little please ?

you're using a weak table to cache some results, to avoid some costly
calculations or data retrieval. this is valid only as long as you know
that those expensive operations will give the same result every time.
when some condition changes, the result changes as well, and the cache
isn't valid.

what you're trying to do is to act at the very moment that condition
changes, to mark the cached data as invalid.

you can turn the problem around, to make sure that you only cache
invariant results:

for example, if what you want to avoid is an expensive calculation
that only depend on input parameters, then you should use all those
parameters as the cache's key.

a different example would be to cache a DB retrieval/template
rendering, there you should use not only the DB key at cache key, but
also some kind of record version.  that way, you don't have to
invalidate the old version.  just register the new version and the old
one will eventually be purged.

of course, if you can easily hook the 'modification' time, you can
just delete the cache entry.

-- 
Javier