Beispiel #1
0
 /// <summary>
 /// Constructor for TOneModel that implements <see cref="IUniquelyIdentifiable{TId}"/>.
 /// </summary>
 /// <param name="service"></param>
 /// <param name="cache"></param>
 /// <param name="flushCacheDelegateAsync"></param>
 /// <param name="options"></param>
 public SlaveToMasterAutoCache(ICrudable service,
                               IDistributedCache cache, FlushCacheDelegateAsync flushCacheDelegateAsync = null,
                               AutoCacheOptions options = null)
     : this(service, item => ((IUniquelyIdentifiable <SlaveToMasterId <TId> >)item).Id, cache,
            flushCacheDelegateAsync, options)
 {
 }
        /// <summary>
        /// Constructor for TModel that does not implement <see cref="IUniquelyIdentifiable{TId}"/>, or when you want to specify your own GetKey() method.
        /// </summary>
        /// <param name="getIdDelegate"></param>
        /// <param name="cache"></param>
        /// <param name="flushCacheDelegateAsync"></param>
        /// <param name="options"></param>
        public AutoCacheBase(GetIdDelegate <TModel, TId> getIdDelegate, IDistributedCache cache, FlushCacheDelegateAsync flushCacheDelegateAsync = null, AutoCacheOptions options = null)
        {
            InternalContract.RequireNotNull(getIdDelegate, nameof(getIdDelegate));
            InternalContract.RequireNotNull(cache, nameof(cache));
            if (options == null)
            {
                options = new AutoCacheOptions
                {
                    AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(1)
                };
            }

            CacheIdentity = Guid.NewGuid().ToString();
            Cache         = cache;
            Options       = options;
            GetIdDelegate = getIdDelegate;
            CacheOptions  = new DistributedCacheEntryOptions
            {
                AbsoluteExpirationRelativeToNow = Options.AbsoluteExpirationRelativeToNow,
                SlidingExpiration = Options.SlidingExpiration
            };

            if (flushCacheDelegateAsync == null)
            {
                if (cache is IFlushableCache flushableCache)
                {
                    flushCacheDelegateAsync = flushableCache.FlushAsync;
                }
            }
            _flushCacheDelegateAsync = flushCacheDelegateAsync;
        }
Beispiel #3
0
 /// <summary>
 /// Constructor for TModel that does not implement <see cref="IUniquelyIdentifiable{TId}"/>, or when you want to specify your own GetKey() method.
 /// </summary>
 /// <param name="service"></param>
 /// <param name="cache"></param>
 /// <param name="getIdDelegate"></param>
 /// <param name="flushCacheDelegateAsync"></param>
 /// <param name="options"></param>
 public CrudAutoCache(ICrudable service, GetIdDelegate <TModel, TId> getIdDelegate,
                      IDistributedCache cache, FlushCacheDelegateAsync flushCacheDelegateAsync = null,
                      AutoCacheOptions options = null)
     : base(service, getIdDelegate, cache, flushCacheDelegateAsync, options)
 {
 }
Beispiel #4
0
 /// <summary>
 /// Constructor for TOneModel that does not implement <see cref="IUniquelyIdentifiable{TId}"/>, or when you want to specify your own GetKey() method.
 /// </summary>
 /// <param name="service"></param>
 /// <param name="cache"></param>
 /// <param name="getIdDelegate"></param>
 /// <param name="flushCacheDelegateAsync"></param>
 /// <param name="options"></param>
 public SlaveToMasterAutoCache(ICrudable service,
                               GetIdDelegate <TManyModel, SlaveToMasterId <TId> > getIdDelegate, IDistributedCache cache,
                               FlushCacheDelegateAsync flushCacheDelegateAsync = null, AutoCacheOptions options = null)
     : base(service, getIdDelegate, cache, flushCacheDelegateAsync, options)
 {
 }
 /// <summary>
 /// Constructor for TModel that implements <see cref="IUniquelyIdentifiable{TId}"/>.
 /// </summary>
 /// <param name="service"></param>
 /// <param name="cache"></param>
 /// <param name="flushCacheDelegateAsync"></param>
 /// <param name="options"></param>
 public CrudAutoCache(ICrudable <TModel, TId> service, IDistributedCache cache,
                      FlushCacheDelegateAsync flushCacheDelegateAsync = null, AutoCacheOptions options = null)
     : this(service, item => ((IUniquelyIdentifiable <TId>)item).Id, cache, flushCacheDelegateAsync, options)
 {
 }
 /// <summary>
 /// Constructor for TModel that implements <see cref="IUniquelyIdentifiable{TId}"/>.
 /// </summary>
 /// <param name="cache"></param>
 /// <param name="flushCacheDelegateAsync"></param>
 /// <param name="options"></param>
 public AutoCacheBase(IDistributedCache cache, FlushCacheDelegateAsync flushCacheDelegateAsync = null, AutoCacheOptions options = null)
     : this(item => ((IUniquelyIdentifiable <TId>)item).Id, cache, flushCacheDelegateAsync, options)
 {
 }