Peter Hunsberger wrote:
> I'm still confused:
> 
> 1) Why can't the validity itself figure out whatever it needs to know.
>  Eg, go look at the file to see if has been modified?

The validity object is just a value object - it has to be serializable
in order to be stored persistently by the cache.
Sure, you could store e.g. the file name in the object and inside
the isValid() method open the file etc. But what about resources
fetched via http or any other protocol? You start mixing value
objects and controls.

> 
> 2) Who generates the new source validity for the second 
> check?  I can't see how sequence of methods would be actually 
> invoked...
> 
It's the source that generates the validity objects. For example
for a file you end up with a file source object that generates
the validity object containing the last modification date of the
file.
In the case of caching, e.g. the file generator resolves a source
object for the given source and asks this source object for
a validity object. This validity object is then stored in the
cache. With any further request, the validity object is fetched
from the cache and the isValid() method is invoked. If this
method is not able to determine if the cached response is still
valid or invalid it returns the constant for UNKNOWN. If it's
unknown the file generator is asked to deliver a new validity
object which is then passed into the isValid(SourceValidity)
method.

> Storing all the knowledge the validity needs to determine 
> validity within the validity itself seems like the only thing 
> that makes sense?
> 
> > So, in the general this method is imho needed ;)
> 
> I'll take your word for it, perhaps the real question is, if 
> I'm implementing a caching generator what do I really need to 
> worry about?
> 
:) You just have to implement the correponding interface that
makes the component cacheable. The objects you return by the
methods of this interface should be serializable. If you
implement your own source validity object make sure that either
isValid() works or isValid(SourceValidity) works ;)

Carsten

Reply via email to