Question

We need to cache data in our Sharepoint farm in a distributed manner which we previously have solved with our own logic building upon HttpRuntime.Cache and some custom syncronization between the servers.

I'm considering the possibility to move this to the Distributed Cache instead. I can't find much about storing your own custom data on it so I'm interpreting that as that we aren't really supposed to do that.

Regardless, I've found a resource that describes how we can access the distributed cache ourselves, but I'm hesitant whether this would come with consequences in regards to performance or stability.

Would it be considered acceptable practice to store custom data on the Distributed Cache? Are there any pitfalls to look out for?

Was it helpful?

Solution

Unfortunately, you are not supposed to use the default App Fabric cluster that is installed with SharePoint prerequisites. Looks like it's unsupported by Microsoft.

Do not use the AppFabric cache cluster supporting your SharePoint Server 2013 farm. Run your separate AppFabric cache cluster for your custom applications on separate servers from the servers dedicated to your SharePoint Server 2013 farm.

The recommendation is to set up your own separate App Fabric cluster.

However, if you want to try accessing the default App Fabric cluster for R&D purposes, here is a working example.

Working example with Server-side object model

    static void Main(string[] args)
    {
        List<DataCacheServerEndpoint> servers = new List<DataCacheServerEndpoint>();
        servers.Add(new DataCacheServerEndpoint("server.domain", 22233));
        DataCacheFactoryConfiguration configuration = new DataCacheFactoryConfiguration();
        configuration.ChannelOpenTimeout = TimeSpan.FromSeconds(120);
        configuration.IsCompressionEnabled = false;
        configuration.MaxConnectionsToServer = 10;
        configuration.RequestTimeout = TimeSpan.FromSeconds(120);
        configuration.Servers = servers;
        configuration.TransportProperties.MaxBufferSize = 1000000;
        DataCacheFactory dataCacheFactory = new DataCacheFactory(configuration);
        DataCache cache = dataCacheFactory.GetCache("DistributedDefaultCache_" + SPFarm.Local.Id);

        if (cache.Get("MyKEY") == null)
        {
            cache.Add("MyKEY", DateTime.Now);
        }
        DateTime dt = (DateTime)cache.Get("MyKEY");
        Console.WriteLine(dt);
    }

Related post

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top