Cache Persistance Without Memory?

Topics: Caching Application Block
Apr 16, 2007 at 8:49 PM
Is it possible to use the Cache block with a persisted store (database) and have it not store the data in memory. In other words, I want to use the cache block to age data I put in the store but the type of data I'm putting in there wouldn't be stored up in memory. Essentially you would just be leveraging the api to store data and manage when things expire and get cleared out (of the backing store). Thanks for any input.

adam
Apr 16, 2007 at 9:18 PM
No there's no way of doing this without significant changes to the block. The block was designed with the assumption that the data is stored in-memory (and optionally written back to a persistent store).

Tom
Apr 17, 2007 at 1:53 PM

tomhollander wrote:
No there's no way of doing this without significant changes to the block. The block was designed with the assumption that the data is stored in-memory (and optionally written back to a persistent store).

Tom


Yeah I've been looking at the code. Seems like what I am talking about would be possible. I basically want to just use the database as my cache and leverage the entlib config settings and logic, etc.

adam
Apr 27, 2007 at 5:41 PM

tomhollander wrote:
No there's no way of doing this without significant changes to the block. The block was designed with the assumption that the data is stored in-memory (and optionally written back to a persistent store).

Tom


Tom,

I was able to easily get this working to allow it cache directly to the backing store. My question is how would you actually implement that? For my test code I created a new app block with the entlib cache block as a starting code base. I'm thinking another approach would be to have different implementations of the CacheOperations interface? It could also just be a mode flag in the Cache class to ignore the memory cache code when needed. All I did to pull this off was to add a Get() method to the backing store and strip out going to memory in the Cache class. Instead I just go to the backing store. I'm wondering what everyone's thoughts on this are.

thanks!

adam
Jun 12, 2007 at 7:23 AM
We also have about the same requirement\plan here too; to adopt the Caching app in web farm.

I put in codes into the GetData() and Count in Cache class, to check the backingStore actuall reference type. If backingStore is BaseBackingStore, which is used for db and isolated, then it will do\get stuff from the real backend source, not the in-memory hashtable.

I have to twick also the BaseBackingStore to have a new method (inheriting a new interface) to load 1 data from the db, and this chg affecting the IsolatedStorageBackingStore

Next I'm gonna workup a custom flag\setting from config that will kick up these special codings. Want to retain the existing design and behavior as much intact for future upgrade.

exp:
public object GetData(string key)
{ ...
if ((backingStore as BackingStoreImplementations.BaseBackingStore) != null)
cacheItemBeforeLock = ((IBackingStoreEx)backingStore).Load(key);
else
cacheItemBeforeLock = (CacheItem)inMemoryCachekey;