我无法在 appfabric 缓存中存储大量对象,怎么办?
I can't store a large list of object in the appfabric cache, how to do?
我有一个包含 10500 个对象的列表。
当我试图将它放入缓存中时,出现了异常。
然后我将列表对象数减少到 9000,然后缓存工作正常。
谁能告诉我如何将所有列表存储在缓存中?
下面是我的 web.config 中的 dataCacheClient :
<dataCacheClient requestTimeout="600000"
channelOpenTimeout="12000"
maxConnectionsToServer="1">
<hosts>
<host name="Platform.Almanhal.local" cachePort="22233" />
</hosts>
<transportProperties connectionBufferSize="131072"
maxBufferPoolSize="568435456"
maxBufferSize="183886080"
maxOutputDelay="2"
channelInitializationTimeout="60000" />
</dataCacheClient>
下面是我用来存储此列表的 appfabric api:
public T Data<T>(string cacheKey, int expirationSeconds, Func<T> method)
{
T data = default(T);
try
{
string key = GetEncryptedKey(cacheKey);
var cache = GetFromCache(key);
data = cache == null ? default(T) : (T)cache;
if (data == null)
{
data = method();
if (expirationSeconds > 0 && data != null)
{
lock (sync)
{
PutInCache(key, data, TimeSpan.FromSeconds(expirationSeconds));
}
}
Logger.LogInfo(string.Format("{0} Loaded From DB", typeof(T).GetProperties()[2].PropertyType.Name));
}
else
{
Logger.LogInfo(string.Format("{0} Loaded From Cache", typeof(T).GetProperties()[2].PropertyType.Name));
}
}
catch (Exception ex)
{
Logger.LogInfo(ex.InnerException.Message);
}
return data;
}
PutInCache 函数如下:
public void PutInCache(string key, object obj, TimeSpan tspan)
{
//TracingLibrary.TraceEvents.AddEvent("Inside Put in Cache");
try
{
_cache.Put(key, obj, tspan);
}
catch (Exception e)
{
string msg = e.InnerException.ToString();
Logger.LogInfo(string.Format("Cannot put object in cache {0}, \nException: {1} \nMessage:{2}", key, e.InnerException.ToNullOrString(), e.Message.ToNullOrString()));
//write to logger ("Exception putting in cache", e.InnerException);
}
}
这是异常消息:
ErrorCode:SubStatus:There is a temporary failure.
Please retry later. (One or more specified cache servers are
unavailable, which could be caused by busy network or servers. For
on-premises cache clusters, also verify the following conditions.
Ensure that security permission has been granted for this client
account, and check that the AppFabric Caching Service is allowed
through the firewall on all cache hosts. Also the MaxBufferSize on the
server must be greater than or equal to the serialized object size
sent from the client.)
答案在错误信息中:
the MaxBufferSize on the server must be greater than or equal to the
serialized object size sent from the client
您在集群配置的 advancedProperties 部分进行设置:
<advancedProperties>
<transportProperties maxBufferSize="183886080" />
</advancedProperties>
我有一个包含 10500 个对象的列表。 当我试图将它放入缓存中时,出现了异常。 然后我将列表对象数减少到 9000,然后缓存工作正常。
谁能告诉我如何将所有列表存储在缓存中?
下面是我的 web.config 中的 dataCacheClient :
<dataCacheClient requestTimeout="600000"
channelOpenTimeout="12000"
maxConnectionsToServer="1">
<hosts>
<host name="Platform.Almanhal.local" cachePort="22233" />
</hosts>
<transportProperties connectionBufferSize="131072"
maxBufferPoolSize="568435456"
maxBufferSize="183886080"
maxOutputDelay="2"
channelInitializationTimeout="60000" />
</dataCacheClient>
下面是我用来存储此列表的 appfabric api:
public T Data<T>(string cacheKey, int expirationSeconds, Func<T> method)
{
T data = default(T);
try
{
string key = GetEncryptedKey(cacheKey);
var cache = GetFromCache(key);
data = cache == null ? default(T) : (T)cache;
if (data == null)
{
data = method();
if (expirationSeconds > 0 && data != null)
{
lock (sync)
{
PutInCache(key, data, TimeSpan.FromSeconds(expirationSeconds));
}
}
Logger.LogInfo(string.Format("{0} Loaded From DB", typeof(T).GetProperties()[2].PropertyType.Name));
}
else
{
Logger.LogInfo(string.Format("{0} Loaded From Cache", typeof(T).GetProperties()[2].PropertyType.Name));
}
}
catch (Exception ex)
{
Logger.LogInfo(ex.InnerException.Message);
}
return data;
}
PutInCache 函数如下:
public void PutInCache(string key, object obj, TimeSpan tspan)
{
//TracingLibrary.TraceEvents.AddEvent("Inside Put in Cache");
try
{
_cache.Put(key, obj, tspan);
}
catch (Exception e)
{
string msg = e.InnerException.ToString();
Logger.LogInfo(string.Format("Cannot put object in cache {0}, \nException: {1} \nMessage:{2}", key, e.InnerException.ToNullOrString(), e.Message.ToNullOrString()));
//write to logger ("Exception putting in cache", e.InnerException);
}
}
这是异常消息:
ErrorCode:SubStatus:There is a temporary failure. Please retry later. (One or more specified cache servers are unavailable, which could be caused by busy network or servers. For on-premises cache clusters, also verify the following conditions. Ensure that security permission has been granted for this client account, and check that the AppFabric Caching Service is allowed through the firewall on all cache hosts. Also the MaxBufferSize on the server must be greater than or equal to the serialized object size sent from the client.)
答案在错误信息中:
the MaxBufferSize on the server must be greater than or equal to the serialized object size sent from the client
您在集群配置的 advancedProperties 部分进行设置:
<advancedProperties>
<transportProperties maxBufferSize="183886080" />
</advancedProperties>