we are using the ORM mapper to load and cache data from a database. The data in the database is modified by different applications not using the Telerik ORM mapper.
So from my point of view the L1 cache needs no invalidation because the cache data is lost in case the DBContext object is destroyed (would be in case of an ASP.NET application after the complete request was worked). The L2 cache on the other hand needs a manual invalidation. Now my question would be, where I can find the API to remove an item from the cache manually and also trigger the invalidation process on the other machines hosting the same L2 cache (ORM cache cluster). I am using the domain model and the DBContext and I can not find the feature in there.
thx for your support
Ibrahim
5 Answers, 1 is accepted
The context base class has a protected method GetScope(). Just add a method on a second partial class parallel to your generated context like:
public void EvictAll(Type t)
{
GetScope().Database.Cache.EvictAll(t);
}
Regards,
Jan Blessenohl
the Telerik team
<
openaccess xmlns="http://www.telerik.com/OpenAccess">
<
backendconfigurations>
<
backendconfiguration id="mssqlConfiguration" backend="mssql">
<l2CacheEnabled>true</l2CacheEnabled> <l2QueryCacheEnabled>true</l2QueryCacheEnabled>
<
l2CacheMaxObjects>1200</l2CacheMaxObjects>
<l2CacheClusterTransport>MSMQ</l2CacheClusterTransport> <l2CacheClusterTransport.multicastaddr>224.1.1.1:666</l2CacheClusterTransport.multicastaddr> <l2CacheClusterTransport.useTracing>true</l2CacheClusterTransport.useTracing> <performanceCounter>true</performanceCounter> <pmCacheRefType>STRONG</pmCacheRefType> </backendconfiguration> </backendconfigurations> </openaccess>
BR
Ibrahim
in the previous post you stated that you are using the domain model. In this case, the app.config is not
read, and the backend configuration must be given programmatically like
var be = new BackendConfiguration();
be.SecondLevelCache.Enabled = true;
be.SecondLevelCache.CacheQueryResults = true;
be.SecondLevelCache.Synchronization.Enabled = true;
be.SecondLevelCache.Synchronization.MulticastAddress = "224.1.1.1:666";
and then this be instance must be used while the context is created.
Please also have a look at this blog post:
http://blogs.telerik.com/openaccessteam/posts/11-04-20/setting_advanced_runtime_options.aspx
Thomas
the Telerik team
1. I am a little confused because at the end of help article http://www.telerik.com/help/openaccess-orm/2nd-level-cache.html, it is said it is not possible to set the level 2 cache invalid manually. So the answer in this thead is wrong, or the documentation is wrong or there is a misunderstanding on my side.Please clarify.
2. Would you pls send me a link to the documentation or a short tutorial how I can remove items from L2 cache manually because we are modifying data using stored procedures. The Stored Procedure returns as a result a list of primary key ids, that I would like to use to build the objectkey in order to identiy the cache item.
thank u
- I believe that both the documentation and the answer in this thread are correct but I do understand your confusion. Here is some clarification:
- The documentation describes the IObjectScope.Evict() method and using that method you do not touch the Level 2 cache as this cache is shared among all object scopes.
- The answer you have seen in this thread from Jan is about the following API: Database.Cache.EvictAll()(there is also a method Database.Cache.Evict()). This API is on the Database object and it touches the Level 2 cache so that is the way for you to evict instances out of the cache.
- You said your stored procedures return id values. At the moment we have not cerated overloads of the Database.Cache.Evict() method that take ObjectKey objects as parameters, but this is still the method call for you in order to remove instances from the cache using their keys. There is an overload of the Evict() method that takes an IObjectId as a parameter and here is how you can create an IObjectId having just the value of your objects ids:
int
animalId = 3;
//suppose this has been returned by your Stored Procedure
IObjectId oid = Database.OID.ParseObjectId(
typeof
(Animal), animalId);
Database db = Database.Get(...);
// You get your database instance.
db.Cache.Evict(oid);
Zoran
the Telerik team