Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Third-Level cache for NHibernate

Our project uses Entity Framework and has 2 type of cache (in-memory, Redis) without any cache provider. Due to lack of second-level cache support in EF we implemented it ourself. So our in-memory cache is simple set of key value pair where key is Id of cache and value is the cached object. We also implemented similar caching to use Redis. For query we look at in-memory cache list and if it is not ther we look at redis and if it does not there we query against the database.

Because entity framework entities has reference to context we can not use entity of DbContext in caching and we need to map it. So we need create a lot of DTOs.

I know that cache is cross-cutting concern so I look for cleaner solution. For this reason, first I decide to use Memcached for In-Memory (instead of using simple list). As second and most importantly I may migrate from EF to NHibernate for its Second-Cache support. I know that first level cache is occupied by session object. So I want to use Memcached for second level cache. But is there any third-level cache for Redis?

like image 949
Seyed Morteza Mousavi Avatar asked Nov 12 '15 14:11

Seyed Morteza Mousavi


1 Answers

One way of implementing a second level cache without creating a lot of DTOs is to use property name value list in a key value list instead of storing a DTO. As per my understanding there is no third level cache in NHibernate. One way of doing this is to implement a custom cache provider which could first look in the Redis and if it can't find it then get values from the Memcached.

like image 184
Low Flying Pelican Avatar answered Sep 27 '22 20:09

Low Flying Pelican