Esempio n. 1
0
        protected override TAggregateRoot GetAggregateRoot(AggregateRootIdentity identity)
        {
            // retrieve from cache or get from base handler and store in cache
            var aggregateRoot = _cache.AddOrGetExisting(GetCacheKey(identity), new Lazy <TAggregateRoot>(() => base.GetAggregateRoot(identity)));

            Contract.Assume(aggregateRoot != null);

            return(aggregateRoot);
        }
Esempio n. 2
0
        /// <inheritdoc />
        public T AddOrGetExisting <T>(string key, Func <T> factory, TimeSpan?lifeSpan)
        {
            var lazyFactory = (Func <Lazy <T> >)(() => new Lazy <T>(factory));
            var result      = cache.AddOrGetExisting(key, lazyFactory, lifeSpan);

            return(result.Value);
        }
        protected override IDictionary <Type, MethodInfo> GetCachedEntries <TInstance>()
        {
            var type = typeof(TInstance);

            return(_cache.AddOrGetExisting(type.FullName, new Lazy <IDictionary <Type, MethodInfo> >(() => type
                                                                                                     .GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance)
                                                                                                     .Where(m => m.Name == _methodName)
                                                                                                     .Where(m => m.GetParameters().Length == 1)
                                                                                                     .ToDictionary(m => m.GetParameters().First().ParameterType, m => m))));
        }
        private IAggregateRootSynchronizationContext AddOrGetCacheItem(Guid aggregateRootId, string key)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(key));

            return(_cache.AddOrGetExisting(key, new Lazy <IAggregateRootSynchronizationContext>(() => CreateAggregateRootSynchronizationContext(aggregateRootId))));
        }
 public MPQFont GetMPQFont(string resourcePath)
 => cache.AddOrGetExisting($"Font::{resourcePath}", () => MPQFont.LoadFromStream(mpqProvider.GetStream($"{resourcePath}.DC6"), mpqProvider.GetStream($"{resourcePath}.tbl")));