This is a migrated thread and some comments may be shown as answers.

Invalidate L2 Cache

5 Answers 176 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ibrahim Imam
Top achievements
Rank 1
Ibrahim Imam asked on 18 Apr 2011, 05:36 PM
Hello,

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

Sort by
0
Accepted
Jan Blessenohl
Telerik team
answered on 19 Apr 2011, 08:08 AM
Hi Ibrahim Imam,
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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ibrahim Imam
Top achievements
Rank 1
answered on 19 Apr 2011, 05:38 PM
This solution works great except I activate the L2 caching cluster because the cache on machine 2 is not invalidated in case an item becomes updated on machine 1. I used the config I appended in the end of this post on both machines. Because I am not very familar with MSMQ I used the multicastaddr as defined in the Telerik Codesamples. This is ok or what IP and Port I have to use on both machines? Actually I checked the MSMQ using the computer management console and would expect a new messageQueue folder created by the Telerik ORM but there is no change.

<

 

 

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

 

 

0
Accepted
Thomas
Telerik team
answered on 20 Apr 2011, 05:43 PM
Hi Ibrahim Imam,

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

Greetings,
Thomas
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ibrahim Imam
Top achievements
Rank 1
answered on 13 May 2011, 02:01 PM
Hello,

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
0
Zoran
Telerik team
answered on 19 May 2011, 10:19 AM
Hello Ibrahim Imam,

  1.  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.
  2. 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);

Best wishes,
Zoran
the Telerik team
Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
Tags
General Discussions
Asked by
Ibrahim Imam
Top achievements
Rank 1
Answers by
Jan Blessenohl
Telerik team
Ibrahim Imam
Top achievements
Rank 1
Thomas
Telerik team
Zoran
Telerik team
Share this question
or