Why is a cache object stored in a session when using AppFabric?

I first went to AppFabric - caching (aka Ms Velocity) and checked msdn virtual labs.

https://cmg.vlabcenter.com/default.aspx?moduleid=4d352091-dd7d-4f6c-815c-db2eafe608c7

There is code in this example that I am not getting. It creates a cache object and stores it in a session state. The documentation only says:

We need to save the cache object in Session State and get the same instance of this object every time we need to use it.

That's not the way I used the cache in ASP.NET. What is the reason for this template and do I need to use it?

private DataCache GetCache()
{
    DataCache dCache;
    if (Session["dCache"] != null)
    {
        dCache = (DataCache)Session["dCache"];

        if (dCache == null)
            throw new InvalidOperationException("Unable to get or create distributed cache");
    }
    else
    {
        var factory = new DataCacheFactory();
        dCache = factory.GetCache("default");
        Session["dCache"] = dCache;
    }

    return dCache;
}
+3
source share
1 answer

, DataCacheFactory - - , .

, , - DataCacheFactory , DataCache, DataCache , , .

, , DataCacheFactory , , .

+1

Source: https://habr.com/ru/post/1727163/


All Articles