private void CheckItem1AsString(IExternalCache externalCache)
        {
            var item = (string)externalCache.Get("Item 1");

            Assert.IsNotNull(item);
            Thread.Sleep(2000);
            item = (string)externalCache.Get("Item 1");
            Assert.IsNull(item);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Wraps a memory cache in front of an external cache (such as redis) to optimise multiple retrievals per machine.
        /// Key space should be unique within app domain and external-cache database but consistent across nodes in a farm.
        /// Creates a .net MemoryCache instance named "MemoryFrontedExternalCache_{keyspace}" (usually no configuration of
        /// this is required).
        /// </summary>
        /// <param name="keyspace">Key space must be unique within app domain and external-cache database but consistent across nodes in a farm.</param>
        /// <param name="externalCache">The external distributed/network cache to get/store values from/in.</param>
        /// <param name="traceWriter">Optional trace writer for detailed diagnostics.</param>
        public MemoryFrontedExternalCache(string keyspace, IExternalCache externalCache, ITraceWriter traceWriter = null)
        {
            _memoryCache   = new MemoryCache($"{nameof(MemoryFrontedExternalCache)}_{keyspace}");
            _externalCache = externalCache;
            _traceWriter   = traceWriter;

            // external cache keys must be unique within an app domain but common across a farm of servers/services (thus includes keyspace but no guid)
            _cacheKeyPrefixItem = $"{nameof(MemoryFrontedExternalCache)}:{keyspace}:Item:";

            // retrieval locks need to be unique within an instance (as NamedLock has a static dictionary of named locks)
            // as multiple of these caches could be setup within an app domain (such as in testing), we need a guid in the key
            // to ensure each one is only creating named locks against itself.
            _lockKeyPrefixExternalRetrieve = $"{nameof(MemoryFrontedExternalCache)}:{keyspace}:Retrieve:{Guid.NewGuid():N}:";
        }
Exemplo n.º 3
0
 public CreationTimestampedCache(string keyspace, IExternalCache externalCache, ITraceWriter traceWriter = null)
 {
     _cache = new MemoryFrontedExternalCache(keyspace, externalCache, traceWriter);
 }
 public CountCharactersServiceNewImplementation(IExternalCache cache)
 {
     _cache = cache;
 }