The idea behind this new interface is that the rest of the model should not talk
directly to the document cache but rather to an adapter to the cache. For
example, in the old implementation, when the OpenDefinitionsDocument needed to
get the DefinitionsDocument, the code would look like this:
DefinitionsDocument getDocument() {
...
return _cache.get(this);
...
}
public boolean isModifiedSinceSave() {
if(_cache.isDDocInCache(this)){
return getDocument().isModifiedSinceSave();
}
else{
return false;
}
}
But now the code looks like this:
DefinitionsDocument getDocument() {
...
return _cacheAdapter.getDocument();
...
}
public boolean isModifiedSinceSave() {
if(_cacheAdpater.isReady()){
return getDocument().isModifiedSinceSave();
}
else{
return false;
}
}
On the inside of the cache, these DCacheAdapters serve as managers for the
instances of the DefinitionsDocuments. They are responsible for storing the
unique reference to the document. The cache that created it keeps an LRU of
these managers/adapters and tells the manager to discard its document if its
place in the LRU has expired.
|