L2 Cache

14 posts, 0 answers
  1. john
    john avatar
    67 posts
    Member since:
    Jan 2012

    Posted 28 Nov 2012 Link to this post

    Can explain L2 Cache is used under which scenario?
  2. Doroteya
    Admin
    Doroteya avatar
    502 posts

    Posted 29 Nov 2012 Link to this post

    Hello John,

    Generally, Second Level Cache of Telerik OpenAccess ORM is a cache used by all instances of OpenAccessContext created from a single application. It resides in the application process and is populated during read access of the database. More details about its capabilities, how to maintain it and how to set it up, you can read in this set of articles.

    In fact, it is suitable in all scenarios that include multi-threading but its optimal usage is with Web applications. There you have thread pooling and open a new context for all incoming calls. In this scenario, database access is necessary only when the data, which needs to be retrieved is not currently available in the cache. The end result from using 2nd Level Cache is increased efficiency and performance of your application.

    If you have any additional questions, do not hesitate to get back to us.

    Greetings,
    Doroteya
    the Telerik team
    Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
  3. DevCraft banner
  4. john
    john avatar
    67 posts
    Member since:
    Jan 2012

    Posted 29 Nov 2012 Link to this post

    For example I enable the L2 Cache. In search page, I click search button and it will call DB to get data with OpenAccess ORM. Then another user modify one record which is in search result. At this time, if I try to click search button with same parameter, whether it will not get the updated data?
  5. Ady
    Admin
    Ady avatar
    588 posts

    Posted 04 Dec 2012 Link to this post

    Hi Jin Zhi Hao,

     If the object is modified from within the same application (i.e uses the same connection string and credentials) OpenAccess will clear all objects of the type that has been modified and the next time the query is executed the objects will be fetched from the database.
    In case the object is modified by another application you would need to manually evict objects of that type from the L2 cache using the 'context.LevelTwoCache.EvictAll<T>()' method.

    Do get back in case you need further assistance.

    Kind regards,
    Ady
    the Telerik team
    Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
  6. john
    john avatar
    67 posts
    Member since:
    Jan 2012

    Posted 12 Dec 2012 Link to this post

    If my application is a distributed application, whethether the L2 cache will be synchronized in mutipule app servers?
  7. Ady
    Admin
    Ady avatar
    588 posts

    Posted 13 Dec 2012 Link to this post

    Hello Jin Zhi Hao,

     You would need to setup the cache cluster in order to synchronize the caches. You can find more information about the cache cluster, here.

    Do get back in case you need further assitance.

    All the best,
    Ady
    the Telerik team
    Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
  8. john
    john avatar
    67 posts
    Member since:
    Jan 2012

    Posted 20 Dec 2012 Link to this post

    Hi,

    I see your provided link. Whether there is a way to specify the cache is hosted in a standlone cache server? I see your implementation will use MSMQ. Whether there are some delay while synchronize the caches between mutipule server? For example, I have 3 servers which all enable L2 cache. If I modify one record, whether it will refresh cache for updated record in 3 server at the same time?
  9. Ralph Waldenmaier
    Admin
    Ralph Waldenmaier avatar
    202 posts

    Posted 20 Dec 2012 Link to this post

    Hello Jin Zhi Hao,

    The concept, as described in the link before, of the L2 cache is to use MSMQ as a transport layer to inform other participants in the environment about the changes. Basically every OpenAccess database process you are running has it's own data cache. If something is changed, then we generate meta information of what to evict from the cache. Other database processes will be informed, by sending an evict message via the specified multicast address.
    This information is optimized to not send more then needed the actual data is not transmitted. As soon as the evict message arrives at the particular database process, it will be deleted from its data cache.
    Depending on your infrastructure (network speed, etc.), there could be a potential inconsistency in your caches between your Database processes but I strongly believe that this timeframe is very short. 
    At the moment there is no concept in Telerik OpenAccess ORM to use a standalone cache server.

    I hope this information is helpful for you.
    Do come back if you need further assistance.

    Kind regards,
    Ralph
    the Telerik team
    Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
  10. john
    john avatar
    67 posts
    Member since:
    Jan 2012

    Posted 20 Dec 2012 Link to this post

    The cache is store in DB server or app server? Also, whether the cache is stored in memory?
  11. Ralph Waldenmaier
    Admin
    Ralph Waldenmaier avatar
    202 posts

    Posted 20 Dec 2012 Link to this post

    Hi Jin Zhi Hao,

    The cache is stored in the memory of your application.
     
    Feel free to ask if you have any other question.

    Kind regards,
    Ralph
    the Telerik team
    Q3'12 SP1 of OpenAccess ORM packs Multi-Table Entities mapping support. Check it out.
  12. john
    john avatar
    67 posts
    Member since:
    Jan 2012

    Posted 23 Dec 2012 Link to this post

    The cache is stored in DB server or app server?
  13. Viktor Zhivkov
    Admin
    Viktor Zhivkov avatar
    291 posts

    Posted 26 Dec 2012 Link to this post

    Hi Jin,

    Level 2 Cache resides in the memory of the application server. It is available to all callers only in the application domain of the first data context query. This means that if two application use the same OpenAccess model they will not share their Level 2 Cache.

    I hope that this clears things up.

    All the best,
    Viktor Zhivkov
    the Telerik team
    Q3'12 SP1 of OpenAccess ORM packs Multi-Table Entities mapping support. Check it out.
  14. john
    john avatar
    67 posts
    Member since:
    Jan 2012

    Posted 26 Dec 2012 Link to this post

    1.“It is available to all callers only in the application domain of the first data context query”, Whether it means that the cache is available after the first data context query is called, then it will put the data into cache?

    2."This means that if two application use the same OpenAccess model they will not share their Level 2 Cache.", What's the definition for the 'application', different connection string or what else?
  15. Dimitar Tachev
    Admin
    Dimitar Tachev avatar
    67 posts

    Posted 28 Dec 2012 Link to this post

    Hi John,

    1. Yes, the Level 2 Cache is populated during a database access.
    2. Each type of project including web sites are separated applications and have their own application domains. The application does not depend on the number of the different connection string. 

    The 2nd level cache is designed to implement a multithreaded application, where every single thread has its own context. If you need to have the cache working on a higher level (to be shared between many applications) you could use our L2 Cache Cluster.

    It provides the ability to synchronize the L2 caches of many applications that operate on the same database. To achieve this, each modifying transaction sends messages to all participants in the cluster, so they can evict the outdated data. This communication is done in an asynchronous way– there is a very short time-frame, in which one L2 cache could be evicted but another L2 cache could still hold old data.

    If you want to use a L2 cache cluster, you can follow the steps below to enable it:

    1. Create a partial class of your domain model – like in the attached image.

     2. Override the OnDatabaseOpen method with the following code:
    protected override void OnDatabaseOpen(Telerik.OpenAccess.BackendConfiguration backendConfiguration, Telerik.OpenAccess.Metadata.MetadataContainer metadataContainer)
    {
        backendConfiguration.SecondLevelCache.Enabled = true;
        backendConfiguration.SecondLevelCache.Synchronization.Enabled = true;
        backendConfiguration.SecondLevelCache.Synchronization.MulticastAddress = "224.1.1.1:666";
        backendConfiguration.SecondLevelCache.Synchronization.Name = "MSMQ";
     
        base.OnDatabaseOpen(backendConfiguration, metadataContainer);
    }

    In this documentation section you could find more information about working with 2nd Level Cache in a Distributed Environment.

    I hope this helps.

    Regards,
    Dimitar Tachev
    the Telerik team
    Q3'12 SP1 of OpenAccess ORM packs Multi-Table Entities mapping support. Check it out.
Back to Top
DevCraft banner