I'm trying to take advantage of Distributed Cache in SharePoint 2013 programmatically from a console application. I want to store custom objecst inside App Fabric Cache.
Here is the code that throws an error:
List<DataCacheServerEndpoint> servers = new List<DataCacheServerEndpoint>();
servers.Add(new DataCacheServerEndpoint("Myserver.domain", 22233));
DataCacheFactoryConfiguration configuration = new DataCacheFactoryConfiguration();
configuration.ChannelOpenTimeout = TimeSpan.FromSeconds(60);
configuration.IsCompressionEnabled = false;
configuration.MaxConnectionsToServer = 10;
configuration.RequestTimeout = TimeSpan.FromSeconds(60);
configuration.Servers = servers;
configuration.TransportProperties.MaxBufferSize = 200000;
DataCacheFactory dataCacheFactory = new DataCacheFactory(configuration);
DataCache cache = dataCacheFactory.GetDefaultCache(); // <---- Error
dataCacheFactory.GetDefaultCache() throws an error:
Cache referred to does not exist. Contact administrator or use the Cache administration tool to create a Cache.
Addtitional info:
Distributed cache is running on my only development server
Get-CacheHostConfig command returns:
HostName : {hostname}
ClusterPort : 22234
CachePort : 22233
ArbitrationPort : 22235
ReplicationPort : 22236
Size : 410 MB
ServiceName : AppFabricCachingService
HighWatermark : 99%
LowWatermark : 90%
IsLeadHost : True
Get-CacheHost command returns:
HostName : CachePort Service Name Service Status Version Info
-------------------- ------------ -------------- ------------
{hostname}:22233 AppFabricCachingService UP 3 [3,3][1,3]
I've run this powershell comamnd against my current login:
Grant-CacheAllowedClientAccount domain\user
I would be really grateful if someone could shed some light on this problem. Why do I get this error? Maybe I'm doing something wrong?
Update
I've tried the same code on a completely different SharePoint Farm. There is the same error. So, it's not server-specific. I've managed to make this code work by getting the Cache by the full name like so:
DataCache cache = dataCacheFactory.GetCache("DistributedDefaultCache_bbc9d9fe-ea79-477a-890c-867b1ae0c91b");
You can get the full name by running this PowerShell command:
Get-Cache |Where-Object{$_.CacheName -like "*Default*"}|fl