locked
Cache and Session RRS feed

  • Question

  • Are there specific cache and session providers in the Orchard Framework that I can/should use within my controllers? - I assumed that cache and session is isolated into each tenant shell?

    Thanks


    retroviz
    Sunday, September 12, 2010 5:08 PM

Answers

  • Ah, great question, thanks. Yes, if you go through the Orchard APIs for caching (look at the Caching namespace in Orchard.Framework, in particular ICacheManager of which you can grab an implementation from your controllers through IoC) it will be per tenant. If you go through the .NET APIs it won't be, naturally.

    Session is not the subject of a specific API so far because tenant separation of session currently happen naturally as a side-effect to our usage of domain names to discriminate tenants. If/when we can discriminate tenants by path, we will have this problem and will probably have to introduce an abstraction.

    When that happens, any old code using session might have to be revised. Personally I avoid session as much as I can but I understand how that could be a problem.

    Might be a good contribution to make even though at the moment it wouldn't do much, just to be more future-proof.

    Monday, September 13, 2010 6:36 PM
  • You never just store objects in the cache: you try to retrieve them and provide the method to create them if they are not found.

    Rather than use session, you might want to store the shopping cart in the database as user data, so that it is resilient to session loss, browser/computer crashes, etc.

    Tuesday, September 14, 2010 12:08 AM

All replies

  • Ah, great question, thanks. Yes, if you go through the Orchard APIs for caching (look at the Caching namespace in Orchard.Framework, in particular ICacheManager of which you can grab an implementation from your controllers through IoC) it will be per tenant. If you go through the .NET APIs it won't be, naturally.

    Session is not the subject of a specific API so far because tenant separation of session currently happen naturally as a side-effect to our usage of domain names to discriminate tenants. If/when we can discriminate tenants by path, we will have this problem and will probably have to introduce an abstraction.

    When that happens, any old code using session might have to be revised. Personally I avoid session as much as I can but I understand how that could be a problem.

    Might be a good contribution to make even though at the moment it wouldn't do much, just to be more future-proof.

    Monday, September 13, 2010 6:36 PM
  • Hi Bertrand,

    Thanks for the clarification.

    Can you give me an example of storing items in the cache via the DefaultCacheManager (it only appears to have methods for retrieving items from the cache - but perhaps I am missing something)

    We want to use session for storing a customer shopping cart rather than hitting the db every time so will probably just write a session provider for this 

    Thanks,

    Ben


    retroviz
    Monday, September 13, 2010 7:59 PM
  • You never just store objects in the cache: you try to retrieve them and provide the method to create them if they are not found.

    Rather than use session, you might want to store the shopping cart in the database as user data, so that it is resilient to session loss, browser/computer crashes, etc.

    Tuesday, September 14, 2010 12:08 AM
  • Okay, I get it - 

          ViewData["Message"] =
            _cache.Get<string, DateTime>("SomeKey", ctx => {
              return DateTime.Now;
            });
    

    Any plans to use the new caching features in .net 4 (System.Runtime.Caching)? Would be great if we could also pass our own cache dependencies.

    Regarding session usage, we are aware of the implications of using session and tend to only use it as a temporary storage location rather than hitting the db.

     

    Thanks for your help

    Ben


    retroviz
    Tuesday, September 14, 2010 7:31 AM
  • We have no such plans at the moment but if you want to get it in I suppose we could take it as a patch.
    Tuesday, September 14, 2010 10:34 PM