The document cache is a structure that maps OpenDefinitionsDocuments to DefinitionsDocuments (which contain
the actual document text). Since the latter can consume a lot of memory, the cache virtualizes some of them
using DefinitionsDocument reconstructors (DDReconstructor). It tries to limit the number of
DefinitionsDocuments loaded in memory at one time, but it must of course retain all modified
DefinitionsDocuments.
The cache creates a DocManager for each OpenDefinitionsDocument entered (registered) in the cache. The managers
maintain the actual links to DefinitionsDocuments. Since the Managers themselves implement the DCacheAdapter
interface, the model goes directly to the manager to get the instance of the DefinitionsDocument.
When a document is accessed through the document manager by the model, the cache informs the manager, which
tells the active queue to add the manager to the end of the queue--if it isn't already in the queue. If the
active queue had already reached maximum size, it deletes the last document in the queue to keep the queue from
growing larger than its maximum size.
The resident queue only contains documents that have not been modified since their last save (except in the process
of responding to notification that a document has been modified). When a document is modified for the first time,
it is immediately removed from the resident queue and marked as UNMANAGED by its document manager. An
UNMANAGED document remains in memory until it is saved or closed without being saved. If such a document is
saved, it is inserted again in the resident queue.
Since the cache and document managers can both be concurrently accessed from multiple threads, the methods in the
DocumentCache and DocManager classes are synchronized. Some operations require locks on both the cache and a
document manager, but the code is written so that none of require these locks to be held simultaneously.
|