This project is read-only.

Possible Issue with Cache System

Topics: APIs, General
Jun 13, 2014 at 10:36 AM
While trying to understand the caching system (RecoverableTextAndVersion, IObjectCache etc.) I found following potential issue:

In AddOrAccess of IObjectCache only the first WeakAction (evictor) is registered. This may be a problem if a single IObjectCache is used for the same object from different call sites. The call site I identified (there may be more) is RecoverableCachedObjectSource, the base class of RecoverableTextAndVersion. This means each RecoverableTextAndVersion will try to register a WeakAction, but only the first will succeed, all other instances will have their callback ignored.

This means once the corresponding TextAndVersion is evicted from the cache only one RecoverableTextAndVersion will get notified and be able to save itself to temporary storage. However on next access any of the RecoverableTextAndVersion will try to recover the text - even if it was an instance which didn't get around to save on eviction. This will probably result in a null reference exception due to the 'storage' field being null.

From what I can tell multiple RecoverableTextAndVersion could be created for the same TextAndVersion from the public API, though it probably will not happen in "normal" workflow, so this may not be high priority to fix - but its a dangerous trap in the design of the internal API.