/// <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); }
public CacheService( IObjectCache objectCache, IEatRegeratorAPIClient eatClient) { _objectCache = objectCache; _eatClient = eatClient; }
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 }
protected BaseManager(IRepository <TEntity> repository, IObjectCache cache, object cacheLock) { Repository = repository; Cache = cache; CacheLock = cacheLock; HasCache = true; }
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"); } } } }
public virtual IList GetObjects() { IObjectCache cache = GetObjectCache(); IList cachedObjects = GetCacheObjects(cache); return(cachedObjects); }
private PipelineGraph(ProfileManager profileManager, GenericsPluginGraph genericsGraph, GraphLog log) { _profileManager = profileManager; _genericsGraph = genericsGraph; _log = log; _transientCache = new MainObjectCache(); }
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 }
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 }
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); }
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); }
private void findCache1() { _cache1 = _lifecycle.FindCache(); var cache1 = _lifecycle.FindCache(); Assert.AreSame(_cache1, cache1); }
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); }
public CragsManager(ICragsRepository cragsRepository, ICacheHandler cacheHandler, IStatisticsService statisticsService, IElasticService elasticService) : base(cragsRepository) { _cragsRepository = cragsRepository; _cragsCache = cacheHandler.CragsCache; _cragsCacheLock = cacheHandler.CragsCacheLock; _statisticsService = statisticsService; _elasticService = elasticService; }
/// <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()); }
private void findCache3() { _cache3 = _lifecycle.FindCache(); Assert.AreSame(_cache3, _lifecycle.FindCache()); Assert.AreSame(_cache3, _lifecycle.FindCache()); Assert.AreSame(_cache3, _lifecycle.FindCache()); }
public RootPipelineGraph(PluginGraph pluginGraph) { _pluginGraph = pluginGraph; _transientCache = new NulloTransientCache(); _profiles = new Cache <string, IPipelineGraph>( name => new ComplexPipelineGraph(this, _pluginGraph.Profile(name), new NulloTransientCache())); }
public RootPipelineGraph(PluginGraph pluginGraph) { _pluginGraph = pluginGraph; _transientCache = new NulloTransientCache(); _profiles = new Cache<string, IPipelineGraph>( name => new ComplexPipelineGraph(this, _pluginGraph.Profile(name), new NulloTransientCache())); }
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; }
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); }
//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); }
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); }
public AreasManager(IAreasRepository areasRepository, ICacheHandler cacheHandler, IStatisticsService statisticsService, IElasticService elasticService) : base(areasRepository) { _areasRepository = areasRepository; _cragsCache = cacheHandler.CragsCache; _cragsCacheLock = cacheHandler.CragsCacheLock; _statisticsService = statisticsService; _elasticService = elasticService; }
public SingletonLifecycleTester() { theContext = MockRepository.GenerateMock <ILifecycleContext>(); theLifecycle = new SingletonLifecycle(); theCache = MockRepository.GenerateMock <IObjectCache>(); theContext.Stub(x => x.Singletons).Return(theCache); }
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]); }
public WebDirectoryCache( IObjectCacheFactory cacheFactory, IPageCache pageCache ) { _cache = cacheFactory.Get(CACHEKEY); _pageCache = pageCache; }
public LeasedObjectCache(ILease lease) { if (lease == null) { throw new ArgumentNullException("lease"); } this.lease = lease; this.objectCache = new MainObjectCache(); }
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; }
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; }
public static IMemberAccessor GetMemberAccessor(Type objectType, string memberName, bool readOnly = false, IObjectCache<string> memberCache = null) { return RTHelper.GetMemberAccessor(objectType, memberName, readOnly, memberCache); }
public ComplexPipelineGraph(IPipelineGraph parent, PluginGraph outer, IObjectCache transientCache) { _parent = parent; _outer = outer; _transientCache = transientCache; }
/// <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); } }
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(); }
/// <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); }