Search code examples
nhibernatememcachedsecond-level-cachecollision

memcache as Nhibernate second level cache


I have a question about second level caching with NHibernate and memcache. Suppose the following configuration:

Website A uses DB_A. Data from table X is being cached. Website B uses DB_B. Data from table X is being cached.

Both web apps share a single memcache server.

Now, table X in DB_A and DB_B while having the same schema have different data, so row with PK = 1 in DB_A will NOT be the same data as row with PK = 1 in DB_B.

My question is, will each application clobber the other's data, or is the second level caching smart enough to create cache keys which don't over lap databases.


Solution

  • I'm not sure if you'll have overlapped, overwritten data. You'll need to check what cache-keys are being used. However, interesting reads that you might find helpful:

    http://ayende.com/blog/3976/nhibernate-2nd-level-cache

    http://ayende.com/blog/3112/nhibernate-and-the-second-level-cache-tips

    http://ayende.com/blog/1708/nhibernate-caching-the-secong-level-cache-space-is-shared

    The last one is probably of most use to you. The author did something similar to what you are attempting, except you're making your life easier by (somehow) having no primary key conflicts.