示例#1
0
        /// <summary>
        /// Create a new <see cref="CachingQueryRepository"/>.
        /// </summary>
        /// <param name="queryRepository">
        /// The <see cref="IQueryRepository"/> that will actually load the
        /// security queries. This cannot be null.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="queryRepository"/> cannot be null.
        /// </exception>
        public CachingQueryRepository(IQueryRepository queryRepository)
        {
            if (queryRepository == null)
            {
                throw new ArgumentNullException("queryRepository");
            }

            Repository        = queryRepository;
            Cache             = CacheFactory.CreateSimpleCache <SubjectPermissionTypesTuple, IEnumerable <AccessRuleQuery> >("Access Control Query");
            _cacheInvalidator = new SecurityQueryCacheInvalidator(Cache);
        }
        public void Test_Ctor()
        {
            ICache <string, int>       cache;
            CacheMonitor <string, int> cacheMonitor;

            cache        = CacheFactory.CreateSimpleCache <string, int>("Test");
            cacheMonitor = new CacheMonitor <string, int>(cache);

            Assert.That(cacheMonitor, Has.Property("Cache").SameAs(cache));
            Assert.That(cacheMonitor, Has.Property("ItemsRemoved").Empty);
        }
        /// <summary>
        /// Create a new <see cref="CachingUserRoleRepository"/>.
        /// </summary>
        /// <param name="roleRepository">
        /// The <see cref="IUserRoleRepository"/> this caches. This cannot be null.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="roleRepository"/> cannot be null.
        /// </exception>
        public CachingUserRoleRepository(IUserRoleRepository roleRepository)
        {
            if (roleRepository == null)
            {
                throw new ArgumentNullException("roleRepository");
            }

            RoleRepository    = roleRepository;
            Cache             = CacheFactory.CreateSimpleCache <long, ISet <long> >("User to Role");
            _cacheInvalidator = new UserRoleRepositoryCacheInvalidator(Cache);
        }
示例#4
0
        /// <summary>
        /// Construct a new <see cref="CachingEntityMemberRequestFactory"/>.
        /// </summary>
        /// <param name="factory">
        /// The inner <see cref="IEntityMemberRequestFactory"/> whose results are cached.
        /// This cannot be null.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// No argument can be null.
        /// </exception>
        public CachingEntityMemberRequestFactory(IEntityMemberRequestFactory factory)
        {
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }

            Factory           = factory;
            Cache             = CacheFactory.CreateSimpleCache <long, EntityMemberRequest>("Entity Member Request");
            _cacheInvalidator = new EntityMemberRequestCacheInvalidator(Cache);
            CacheInvalidator  = _cacheInvalidator;
        }
示例#5
0
        /// <summary>
        /// Create a new <see cref="CachingReportToQueryConverter"/>.
        /// </summary>
        /// <param name="converter">
        /// The wrapped converter.
        /// </param>
        public CachingReportToQueryConverter([WithKey(Factory.NonCachedKey)] IReportToQueryConverter converter)
        {
            if (converter == null)
            {
                throw new ArgumentNullException("converter");
            }

            Converter         = converter;
            Cache             = CacheFactory.CreateSimpleCache <CachingReportToQueryConverterKey, CachingReportToQueryConverterValue>("Report To Query");
            _cacheInvalidator = new ReportToQueryCacheInvalidator(Cache);
            _syncRoot         = new object();
        }
        /// <summary>
        /// Create a new <see cref="CachingWorkflowActionsFactory"/>.
        /// </summary>
        /// <param name="fetcher">
        /// The fetcher for the info.
        /// </param>
        public CachingWorkflowActionsFactory(IWorkflowActionsFactory fetcher)
        {
            if (fetcher == null)
            {
                throw new ArgumentNullException("fetcher");
            }

            _fetcher = fetcher;

            Cache = CacheFactory.CreateSimpleCache <CachingWorkflowActionsFactoryKey, CachingWorkflowActionsFactoryValue>("Workflow Action for Type");

            _cacheInvalidator = new WorkflowActionsFactoryInvalidator(Cache);
            _syncRoot         = new object();
        }
        /// <summary>
        /// Create a new <see cref="CachingCalculatedFieldMetadataProvider"/>.
        /// </summary>
        /// <param name="innerProvider">
        /// The <see cref="ICalculatedFieldMetadataProvider"/> that will actually calculate the result. This cannot be null.
        /// </param>
        public CachingCalculatedFieldMetadataProvider(ICalculatedFieldMetadataProvider innerProvider)
            : base("CalculatedFieldMetadata", cacheFactory)
        {
            if (innerProvider == null)
            {
                throw new ArgumentNullException("innerProvider");
            }

            InnerProvider = innerProvider;

            // Note: this class manages two caches:
            // 1. a full cache service for GetCalculatedFieldMetadata
            // 2. a simple unmanaged, non-invalidated, cache for IsCalculatedField.
            _isCalculatedFieldCache = CacheFactory.CreateSimpleCache <long, bool>("IsCalculatedFieldCache", false, 0);
        }
        public void Test_Removal()
        {
            ICache <string, int> cache;
            const string         testKey   = "Test Key";
            const int            testValue = 1234;

            cache = CacheFactory.CreateSimpleCache <string, int>("Test");
            using (CacheMonitor <string, int> cacheMonitor = new CacheMonitor <string, int>(cache))
            {
                Assert.That(cacheMonitor.ItemsRemoved, Is.Empty, "Not empty initially");
                cache.Add(testKey, testValue);
                Assert.That(cacheMonitor.ItemsRemoved, Is.Empty, "Not empty after all");
                cache.Remove(testKey);
                Assert.That(cacheMonitor.ItemsRemoved, Is.EquivalentTo(new [] { testKey }), "Incorrect after remove");
            }
        }
示例#9
0
 /// <summary>
 ///     Creates the per tenant cache.
 /// </summary>
 /// <returns></returns>
 private ICache <long, long> CreatePerTenantCache()
 {
     return(CacheFactory.CreateSimpleCache <long, long>(string.Format("{0}:{1}", "Test Cache", RequestContext.TenantId)));
 }