Using...
- CacheManager.Core v1.1.2
- CacheManager.Couchbase v1.1.2
- CouchbaseNetClient v2.5.4
- Couchbase Server EE v4.5.0
I tried to set-up a caching layer using the Couchbase configuration of CacheManager but it seems that tons of connections are being opened leading to ephemeral port exhaustion on the web servers.
Here is my config set-up:
private static ICacheManager<object> dataCacheFactory { get; set; }
static CacheHelper()
{
var cacheConfig = new ConfigurationBuilder()
.WithCouchbaseCacheHandle("couchbaseClients/couchbase")
.WithExpiration(ExpirationMode.Sliding, new TimeSpan(0, 15, 0))
.Build();
dataCacheFactory = new BaseCacheManager<object>(cacheConfig);
}
And my Couchbase web.config set-up:
<couchbaseClients>
<couchbase useSsl="false">
<servers>
<add uri="http://192.168.1.3:8091/pools" />
</servers>
<buckets>
<add name="default" useSsl="false" password="">
<connectionPool name="custom" maxSize="10" minSize="5" />
</add>
</buckets>
</couchbase>
</couchbaseClients>
When the client gets called:
public static TResult CacheHandler<TResult>(string key, Func<TResult> codeBlock)
{
var cache = dataCacheFactory;
object data = cache.Get(key);
if (data != null)
{
return (TResult)data;
}
else
{
var value = codeBlock();
try
{
cache.Put(key, value);
}
catch (Exception) { }
return value;
}
}
Any guidance would be much appreciated!
Edit: There is no problem with this code on my local machine but when the site is deployed on IIS in a higher traffic environment, what results are the following Windows' events in the Event Viewer:
A request to allocate an ephemeral port number from the global TCP port space has failed due to all such ports being in use.
... and...
TCP/IP failed to establish an outgoing connection because the selected local endpoint was recently used to connect to the same remote endpoint. This error typically occurs when outgoing connections are opened and closed at a high rate, causing all available local ports to be used and forcing TCP/IP to reuse a local port for an outgoing connection. To minimize the risk of data corruption, the TCP/IP standard requires a minimum time period to elapse between successive connections from a given local endpoint to a given remote endpoint.