/// <summary>
        /// ctor
        /// </summary>
        /// <param name="decorated"></param>
        /// <param name="objectCache"></param>
        public CachingTypePropertyProviderDecorator(ITypePropertyProvider decorated, IObjectCache objectCache)
        {
            this.decorated   = decorated;
            this.objectCache = objectCache;

            RegisterDefaultKeyProvider(objectCache);
        }
Пример #2
0
 public CacheService(
     IObjectCache objectCache,
     IEatRegeratorAPIClient eatClient)
 {
     _objectCache = objectCache;
     _eatClient   = eatClient;
 }
Пример #3
0
        public virtual void UpdateIdentity(object obj, string previousIdentity, string newIdentity)
        {
            if (obj == null)
            {
                throw new NullReferenceException("Can't update temporary identity for null object!");                 // do not localize
            }
            KeyStruct key     = GetKey(obj, newIdentity);
            KeyStruct prevKey = GetOldKey(obj, previousIdentity);

            IObjectCache cache = GetObjectCache( );

            object result = cache.LoadedObjects[prevKey];

            if (result != null)
            {
                cache.LoadedObjects[key]     = obj;
                cache.LoadedObjects[prevKey] = null;
            }
            else
            {
                result = cache.UnloadedObjects[prevKey];
                if (result != null)
                {
                    cache.UnloadedObjects[key]     = obj;
                    cache.UnloadedObjects[prevKey] = null;
                }
            }

            LogMessage message = new LogMessage("Updated identity");
            LogMessage verbose = new LogMessage("Type: {0}, New Key: {1}, Previous Key: {2}", obj.GetType(), key, prevKey);

            this.Context.LogManager.Debug(this, message, verbose);             // do not localize
        }
Пример #4
0
 protected BaseManager(IRepository <TEntity> repository, IObjectCache cache, object cacheLock)
 {
     Repository = repository;
     Cache      = cache;
     CacheLock  = cacheLock;
     HasCache   = true;
 }
Пример #5
0
 internal void SetKeyedObject(int key, object value)
 {
     if (key-- == Root)
     {
         if (value == null)
         {
             throw new ArgumentNullException("value");
         }
         if (rootObject != null && ((object)rootObject != (object)value))
         {
             throw new ProtoException("The root object cannot be reassigned");
         }
         rootObject = value;
     }
     else
     {
         IObjectCache cache = GetCacheForWrite();
         if (key < cache.Count)
         {
             cache.SetObjectKey(value, key);
         }
         else
         {
             if (key != cache.Append(value))
             {
                 throw new ProtoException("Internal error; a key mismatch occurred");
             }
         }
     }
 }
Пример #6
0
        public virtual IList GetObjects()
        {
            IObjectCache cache         = GetObjectCache();
            IList        cachedObjects = GetCacheObjects(cache);

            return(cachedObjects);
        }
Пример #7
0
 private PipelineGraph(ProfileManager profileManager, GenericsPluginGraph genericsGraph, GraphLog log)
 {
     _profileManager = profileManager;
     _genericsGraph  = genericsGraph;
     _log            = log;
     _transientCache = new MainObjectCache();
 }
Пример #8
0
        public virtual void RegisterLazyLoadedObject(object obj)
        {
            if (obj == null)
            {
                throw new NullReferenceException("Can't register null object as lazy loaded!");                 // do not localize
            }
            //This may throw if ReadConsistency is Pessimistic and a tx guid has already been set...
            SetTransactionGuid(obj);

            IContext ctx = this.Context;

            IObjectCache cache = GetObjectCache();

            if (cache.AllObjects != null)
            {
                cache.AllObjects.Add(obj);
            }
            KeyStruct key = GetKey(obj);

            cache.UnloadedObjects[key] = obj;
            ctx.ObjectManager.SetObjectStatus(obj, ObjectStatus.NotLoaded);

            LogMessage message = new LogMessage("Registered lazy loaded object");
            LogMessage verbose = new LogMessage("Type: {0}, Key: {1}", obj.GetType(), key);

            ctx.LogManager.Info(this, message, verbose); // do not localize
        }
Пример #9
0
        public virtual void UpdateIdentity(object obj, string previousIdentity, string newIdentity)
        {
            if (obj == null)
            {
                throw new NullReferenceException("Can't update temporary identity for null object!");                 // do not localize
            }
            string key     = GetKey(obj, newIdentity);
            string prevKey = GetKey(obj, previousIdentity);

            IObjectCache cache = GetObjectCache( );

            object result = cache.LoadedObjects[prevKey];

            if (result != null)
            {
                cache.LoadedObjects[key]     = obj;
                cache.LoadedObjects[prevKey] = null;
            }
            else
            {
                result = cache.UnloadedObjects[prevKey];
                if (result != null)
                {
                    cache.UnloadedObjects[key]     = obj;
                    cache.UnloadedObjects[prevKey] = null;
                }
            }
            this.Context.LogManager.Debug(this, "Updated identity", "Type: " + obj.GetType().ToString() + ", New Key: " + key + ", Previous Key: " + prevKey);               // do not localize
        }
Пример #10
0
        public virtual object GetObjectByKey(string keyPropertyName, object keyValue, Type type, bool ignoreObjectNotFound)
        {
            type = AssemblyManager.GetBaseType(type);
            object obj;

            obj = this.Context.AssemblyManager.CreateInstance(type);
            ObjectCancelEventArgs e = new ObjectCancelEventArgs(obj);

            this.Context.EventManager.OnGettingObject(this, e);
            if (e.Cancel)
            {
                return(null);
            }
            this.Context.ObjectManager.SetPropertyValue(obj, keyPropertyName, keyValue);
            this.Context.PersistenceEngine.LoadObjectByKey(ref obj, keyPropertyName, keyValue);
            if (obj == null)
            {
                if (ignoreObjectNotFound == false)
                {
                    throw new ObjectNotFoundException("Object not found!");                     // do not localize
                }
            }
            else
            {
                IList        idKeyParts = this.Context.ObjectManager.GetObjectIdentityKeyParts(obj);
                KeyStruct    key        = GetKey(type, idKeyParts);
                IObjectCache cache      = GetObjectCache();
                obj = cache.LoadedObjects[key];
                ObjectEventArgs e2 = new ObjectEventArgs(obj);
                this.Context.EventManager.OnGotObject(this, e2);
            }
            return(obj);
        }
Пример #11
0
        private void findCache2()
        {
            _cache2 = _lifecycle.FindCache();
            var cache2 = _lifecycle.FindCache();

            Assert.AreSame(_cache2, cache2);
        }
        /// <summary>
        /// ctor
        /// </summary>
        /// <param name="decorated"></param>
        /// <param name="objectCache"></param>
        public CachedPropertyAccessorFactoryDecorator(IPropertyAccessorFactory decorated, IObjectCache objectCache)
        {
            this.decorated   = decorated;
            this.objectCache = objectCache;

            RegisterDefaultKeyProvider(objectCache);
        }
Пример #13
0
        private void findCache1()
        {
            _cache1 = _lifecycle.FindCache();
            var cache1 = _lifecycle.FindCache();

            Assert.AreSame(_cache1, cache1);
        }
Пример #14
0
        public virtual void UnRegisterCreatedObject(object obj)
        {
            if (obj == null)
            {
                throw new NullReferenceException("Can't unregister null object!");                 // do not localize
            }
            IContext ctx = this.Context;

            IObjectCache cache = GetObjectCache();

            cache.AllObjects.Remove(obj);

            KeyStruct key = GetKey(obj);

            cache.LoadedObjects.Remove(key);
            ctx.ObjectManager.SetObjectStatus(obj, ObjectStatus.NotRegistered);

            IIdentityHelper identityHelper = obj as IIdentityHelper;

            if (identityHelper == null)
            {
                throw new NPersistException(string.Format("Object of type {0} does not implement IIdentityHelper", obj.GetType()));
            }

            identityHelper.Reset();

            LogMessage message = new LogMessage("Unregistered created object");
            LogMessage verbose = new LogMessage("Type: {0}, Key: {1}", obj.GetType(), key);

            ctx.LogManager.Info(this, message, verbose);             // do not localize
        }
 public ForumThreadsManager(IForumThreadsRepository forumthreadsRepository, IForumCommentsRepository forumCommentsRepository, ICacheHandler cacheHandler) : base(
         forumthreadsRepository)
 {
     _forumthreadsRepository  = forumthreadsRepository;
     _forumCommentsRepository = forumCommentsRepository;
     _forumCache     = cacheHandler.ForumCache;
     _forumCacheLock = cacheHandler.ForumCacheLock;
 }
        public void SetUp()
        {
            theContext = MockRepository.GenerateMock<ILifecycleContext>();
            theLifecycle = new TransientLifecycle();

            theCache = MockRepository.GenerateMock<IObjectCache>();
            theContext.Stub(x => x.Transients).Return(theCache);
        }
        public RecoverableCachedObjectSource(ValueSource <T> initialValue, IObjectCache <T> cache)
        {
            this.weakInstance   = NoReference;
            this.recoverySource = initialValue;
            this.cache          = cache;

            this.evictAction = new WeakAction <RecoverableCachedObjectSource <T>, T>(this, (o, d) => o.OnEvicted(d));
        }
        public SingletonLifecycleTester()
        {
            theContext = Substitute.For<ILifecycleContext>();
            theLifecycle = new SingletonLifecycle();

            theCache = Substitute.For<IObjectCache>();
            theContext.Singletons.Returns(theCache);
        }
Пример #19
0
 public CragsManager(ICragsRepository cragsRepository, ICacheHandler cacheHandler, IStatisticsService statisticsService, IElasticService elasticService) : base(cragsRepository)
 {
     _cragsRepository   = cragsRepository;
     _cragsCache        = cacheHandler.CragsCache;
     _cragsCacheLock    = cacheHandler.CragsCacheLock;
     _statisticsService = statisticsService;
     _elasticService    = elasticService;
 }
Пример #20
0
 /// <summary>
 /// 设置一个拥有唯一键的缓存对象。若指定的键存在,则将指定的对象进行更新;否则将新增一个缓存键和对象。
 /// </summary>
 /// <param name="cache">派生自 <see cref="IObjectCache"/> 接口的实例。</param>
 /// <param name="key">缓存的键。若该键存在,则更新 value 的值;否则新增一个新缓存字段对象。</param>
 /// <param name="predicate">可使用委托的方式进行运算后将结果设置到指定缓存键中。</param>
 public static void Set <TResult>(this IObjectCache cache, string key, Func <TResult> predicate)
 {
     if (predicate == null)
     {
         throw new ArgumentNullException(nameof(predicate));
     }
     cache.Set(key, predicate.Invoke());
 }
Пример #21
0
        private void findCache3()
        {
            _cache3 = _lifecycle.FindCache();

            Assert.AreSame(_cache3, _lifecycle.FindCache());
            Assert.AreSame(_cache3, _lifecycle.FindCache());
            Assert.AreSame(_cache3, _lifecycle.FindCache());
        }
Пример #22
0
 public RootPipelineGraph(PluginGraph pluginGraph)
 {
     _pluginGraph    = pluginGraph;
     _transientCache = new NulloTransientCache();
     _profiles       =
         new Cache <string, IPipelineGraph>(
             name => new ComplexPipelineGraph(this, _pluginGraph.Profile(name), new NulloTransientCache()));
 }
Пример #23
0
 public RootPipelineGraph(PluginGraph pluginGraph)
 {
     _pluginGraph = pluginGraph;
     _transientCache = new NulloTransientCache();
     _profiles =
         new Cache<string, IPipelineGraph>(
             name => new ComplexPipelineGraph(this, _pluginGraph.Profile(name), new NulloTransientCache()));
 }
Пример #24
0
 public ForumCategoriesManager(IForumCategoriesRepository forumcategoriesRepository, IForumThreadsRepository forumThreadsRepository, IForumCommentsRepository forumCommentsRepository, ICacheHandler cacheHandler) : base(forumcategoriesRepository, cacheHandler.ForumCategoryCache, cacheHandler.ForumCategoryCacheLock)
 {
     _forumcategoriesRepository = forumcategoriesRepository;
     _forumThreadsRepository    = forumThreadsRepository;
     _forumCommentsRepository   = forumCommentsRepository;
     _forumCategoryCache        = cacheHandler.ForumCategoryCache;
     _forumCategoryCacheLock    = cacheHandler.ForumCategoryCacheLock;
 }
Пример #25
0
        public CachedObjectSource(T instance, IObjectCache <T> cache)
        {
            this.weakInstance = new WeakReference <T>(instance);
            this.cache        = cache;

            this.evictAction = new WeakAction <CachedObjectSource <T>, T>(this, (o, d) => o.OnEvicted(d));
            cache.AddOrAccess(instance, this.evictAction);
        }
 protected IObjectCache GetNonTransactionalCache()
 {
     if (nonTransactionalObjectCache == null)
     {
         nonTransactionalObjectCache = new ObjectCache();
     }
     return(nonTransactionalObjectCache);
 }
Пример #27
0
        //TODO: make this class internal (update all references in mobileezy)!!!

        public DelegateMemberAccessor(string memberName, bool readOnly = false, IObjectCache <string> memberCache = null)
            : base(
                RuntimeDelegateFactory.RetrieveMemberGetValueDelegate <TObjectType, TMemberType>(memberName, memberCache),
                readOnly ? null : RuntimeDelegateFactory.RetrieveMemberSetValueDelegate <TObjectType, TMemberType>(memberName, memberCache),
                true)
        {
            MemberName = memberName;
        }
        public SingletonLifecycleTester()
        {
            theContext   = Substitute.For <ILifecycleContext>();
            theLifecycle = new SingletonLifecycle();

            theCache = Substitute.For <IObjectCache>();
            theContext.Singletons.Returns(theCache);
        }
Пример #29
0
 public RoutesManager(IRoutesRepository routesRepository, ICacheHandler cacheHandler, IStatisticsService statisticsService, IElasticService elasticService) : base(routesRepository)
 {
     _routesRepository  = routesRepository;
     _cragsCache        = cacheHandler.CragsCache;
     _cragsCacheLock    = cacheHandler.CragsCacheLock;
     _statisticsService = statisticsService;
     _elasticService    = elasticService;
 }
        public void SetUp()
        {
            theContext = MockRepository.GenerateMock<ILifecycleContext>();
            theLifecycle = new SingletonLifecycle();

            theCache = MockRepository.GenerateMock<IObjectCache>();
            theContext.Stub(x => x.Singletons).Return(theCache);
        }
Пример #31
0
 public AreasManager(IAreasRepository areasRepository, ICacheHandler cacheHandler, IStatisticsService statisticsService, IElasticService elasticService) : base(areasRepository)
 {
     _areasRepository   = areasRepository;
     _cragsCache        = cacheHandler.CragsCache;
     _cragsCacheLock    = cacheHandler.CragsCacheLock;
     _statisticsService = statisticsService;
     _elasticService    = elasticService;
 }
Пример #32
0
        public SingletonLifecycleTester()
        {
            theContext   = MockRepository.GenerateMock <ILifecycleContext>();
            theLifecycle = new SingletonLifecycle();

            theCache = MockRepository.GenerateMock <IObjectCache>();
            theContext.Stub(x => x.Singletons).Return(theCache);
        }
Пример #33
0
        public virtual object TryGetObject(string identity, Type type)
        {
            type = this.Context.AssemblyManager.GetType(type);
            string       key   = type.ToString() + "." + identity;
            IObjectCache cache = GetObjectCache();

            return(cache.LoadedObjects[key]);
        }
Пример #34
0
 public WebDirectoryCache(
     IObjectCacheFactory cacheFactory,
     IPageCache pageCache
     )
 {
     _cache     = cacheFactory.Get(CACHEKEY);
     _pageCache = pageCache;
 }
Пример #35
0
        public LeasedObjectCache(ILease lease)
        {
            if (lease == null)
            {
                throw new ArgumentNullException("lease");
            }

            this.lease = lease;
            this.objectCache = new MainObjectCache();
        }
Пример #36
0
        public PipelineGraph(PluginGraph pluginGraph, IInstanceGraph instances, IPipelineGraph root,
            IObjectCache singletons, IObjectCache transients)
        {
            _pluginGraph = pluginGraph;
            _instances = instances;

            if (root == null)
            {
                _root = this;
                _profiles = new Profiles(_pluginGraph, this);
            }
            else
            {
                _root = root.Root();
                _profiles = root.Profiles;
            }

            _singletons = singletons;
            _transients = transients;
        }
Пример #37
0
        public void CircularDependency()
        {
            cacheUnderTest = new SimpleCache();

            ExceptionAssert.Throws<CircularDependencyException>(() => cacheUnderTest.Resolve("urn:a", NeedA));
        }
 protected IObjectCache GetNonTransactionalCache()
 {
     if (nonTransactionalObjectCache == null)
         nonTransactionalObjectCache = new ObjectCache();
     return nonTransactionalObjectCache;
 }
 public ChildContainerSingletonLifecycle(IObjectCache cache)
 {
     _cache = cache;
 }
Пример #40
0
 public static IMemberAccessor GetMemberAccessor(Type objectType, string memberName, bool readOnly = false, IObjectCache<string> memberCache = null)
 {
     return RTHelper.GetMemberAccessor(objectType, memberName, readOnly, memberCache);
 }
Пример #41
0
 public ComplexPipelineGraph(IPipelineGraph parent, PluginGraph outer, IObjectCache transientCache)
 {
     _parent = parent;
     _outer = outer;
     _transientCache = transientCache;
 }
Пример #42
0
 /// <summary>
 /// Agrega los Paginas de un Perfil al Cache
 /// </summary>
 /// <param name="key"></param>
 /// <param name="dsPaginas">Paginas</param>
 /// <param name="context">El HTTPContext que se esta ejecutando</param>
 private static void AddPaginas(String key, IObjectCache pgs, System.Web.HttpContext context)
 {
     try
     {
         if (context.Cache.Get(key) != null)
             context.Cache.Remove(key); //remuevo si lo encuentra para reemplazarlo
         context.Cache.Add(key,
             pgs, null,
             System.Web.Caching.Cache.NoAbsoluteExpiration,
             TimeSpan.FromMinutes(FormsAuthentication.Timeout.TotalMinutes),
             System.Web.Caching.CacheItemPriority.High, null); //agrego al cache
     }
     catch (Exception)
     {
         //log.Error(ex);
     }
 }
Пример #43
0
 private static IList GetCacheObjects(IObjectCache cache)
 {
     if (cache.AllObjects != null)
     {
         return cache.AllObjects;
     }
     else
     {
         IList objects = new ArrayList() ;
         foreach (object obj in cache.LoadedObjects.Values)
         {
             objects.Add(obj);
         }
         foreach (object obj in cache.UnloadedObjects.Values)
         {
             objects.Add(obj);
         }
         return objects;
     }
 }
 protected static void RegisterANewCache()
 {
     objectCache = new MainObjectCache();
 }
Пример #45
0
 /// <summary>
 /// Agrega los Paginas de un Perfil al Cache
 /// </summary>
 /// <param name="key"></param>
 /// <param name="dsPaginas">Paginas</param>
 /// <param name="context">El HTTPContext que se esta ejecutando</param>
 public static void AddPagesToCache(String key, IObjectCache pgs, System.Web.HttpContext context)
 {
     AddPaginas(key, pgs, context);
 }