コード例 #1
0
 /// <summary>
 /// Gets the global instance of a lookup cache irrespective of the specified type.
 /// </summary>
 /// <param name="type">Cache type.</param>
 /// <returns>The global instance of a lookup cache.</returns>
 public virtual LookupCache GetLookupCache(string type)
 {
     if (globalInstance == null)
     {
         globalInstance = new LookupCache(serviceProvider, null, LookupCache.Global);
     }
     return(globalInstance);
 }
コード例 #2
0
 /// <summary>
 /// Constructs a new local lookup cache loader from the given service provider for the specified type(s).
 /// </summary>
 /// <param name="serviceProvider">Service provider to use for loading the local cache.</param>
 /// <param name="caseSensitive">Indicates whether or not the loaded lookup tables should be case sensitive.</param>
 /// <param name="tableTypes">A list of lookup table types that this loader can load.
 /// If null, the list will be determined based on the first run.</param>
 public LocalLookupCacheLoader(IServiceProvider serviceProvider, bool caseSensitive, params string[] tableTypes)
     : base(serviceProvider, LookupCache.Local, caseSensitive, tableTypes)
 {
     LocalCache = new LookupCache(serviceProvider, new List <ILookupCacheLoader>()
     {
         this
     }, cacheType);
     Parameters = new Dictionary <string, object>();
 }
コード例 #3
0
 /// <summary>
 /// Sets input parameters for this cache loader and reloads the specified cache based on the new parameters.
 /// </summary>
 /// <param name="parameters">New input parameters for the cache loader.</param>
 /// <param name="cache">The cache to reload.</param>
 /// <param name="token">Cancellation token.</param>
 public async Task SetParametersAsync(Dictionary <string, object> parameters, LookupCache cache, CancellationToken token = default)
 {
     Parameters = parameters;
     foreach (var type in supportedTypes)
     {
         cache.RemoveLookupTable(type);
     }
     foreach (var type in supportedTypes)
     {
         await cache.GetLookupTableAsync(type, token);
     }
 }
コード例 #4
0
 /// <summary>
 /// For a user cache type returns an instance of the lookup cache from the user session.
 /// Otherwise it returns a global instance for the application.
 /// </summary>
 /// <param name="type">Cache type.</param>
 /// <returns>An instance of a lookup cache of the given type.</returns>
 public override LookupCache GetLookupCache(string type)
 {
     if (type == LookupCache.User && HttpContext.Current?.Session != null)
     {
         if (!(HttpContext.Current.Session[SessionKey] is LookupCache userCache))
         {
             userCache = new LookupCache(serviceProvider, null, LookupCache.User);
             HttpContext.Current.Session[SessionKey] = userCache;
         }
         return(userCache);
     }
     return(base.GetLookupCache(type));
 }
コード例 #5
0
 /// <summary>
 /// For a user cache type returns an instance of the lookup cache from the user session.
 /// Otherwise it returns a global instance for the application.
 /// </summary>
 /// <param name="type">Cache type.</param>
 /// <returns>An instance of a lookup cache of the given type.</returns>
 public override LookupCache GetLookupCache(string type)
 {
     if (LookupCache.User.Equals(type) && HttpContext.Current != null && HttpContext.Current.Session != null)
     {
         LookupCache userCache = HttpContext.Current.Session[SessionKey] as LookupCache;
         if (userCache == null)
         {
             userCache = new LookupCache(serviceProvider, LookupCache.User);
             HttpContext.Current.Session[SessionKey] = userCache;
         }
         return(userCache);
     }
     return(base.GetLookupCache(type));
 }
コード例 #6
0
        /// <summary>
        /// Loads a lookup table for the specified type into the given lookup cache.
        /// Implementation of the corresponding interface method.
        /// </summary>
        /// <param name="cache">The lookup cache where to populate the lookup table.</param>
        /// <param name="tableType">The type of the lookup table to populate.</param>
        /// <param name="token">Cancellation token.</param>
        public virtual async Task LoadAsync(LookupCache cache, string tableType, CancellationToken token = default)
        {
            void cacheUpdater(LookupTable table)
            {
                cache.CacheLookupTable(table);
                // ensure supportedTypes gets populated
                if (supportedTypes == null)
                {
                    supportedTypes = new HashSet <string>();
                }
                supportedTypes.Add(table.Type);
            }

            await LoadCacheAsync(tableType, cacheUpdater, token);
        }
コード例 #7
0
        /// <summary>
        /// Loads a lookup table for the specified type into the given lookup cache.
        /// Implementation of the corresponding interface method.
        /// </summary>
        /// <param name="cache">The lookup cache where to populate the lookup table.</param>
        /// <param name="tableType">The type of the lookup table to populate.</param>
        public virtual void Load(LookupCache cache, string tableType)
        {
            if (!IsSupported(cache.CacheType, tableType))
            {
                return;
            }

            LoadCache(tableType, delegate(LookupTable table) {
                cache.CacheLookupTable(table);
                // ensure supportedTypes gets populated
                if (supportedTypes == null)
                {
                    supportedTypes = new List <string>();
                }
                if (!supportedTypes.Contains(table.Type))
                {
                    supportedTypes.Add(table.Type);
                }
            });
        }
コード例 #8
0
 /// <summary>
 /// Gets the global instance of a lookup cache irrespective of the specified type.
 /// </summary>
 /// <param name="type">Cache type.</param>
 /// <returns>The global instance of a lookup cache.</returns>
 public LookupCache GetLookupCache(string type)
 {
     if (globalInstance == null) globalInstance = new LookupCache();
     return globalInstance;
 }
コード例 #9
0
        /// <summary>
        /// Loads a lookup table for the specified type into the given lookup cache.
        /// Implementation of the corresponding interface method.
        /// </summary>
        /// <param name="cache">The lookup cache where to populate the lookup table.</param>
        /// <param name="tableType">The type of the lookup table to populate.</param>
        public virtual void Load(LookupCache cache, string tableType)
        {
            if (!IsSupported(cache.CacheType, tableType)) return;

            LoadCache(tableType, delegate (LookupTable table) {
                cache.CacheLookupTable(table);
                // ensure supportedTypes gets populated
                if (supportedTypes == null) supportedTypes = new List<string>();
                if (!supportedTypes.Contains(table.Type)) supportedTypes.Add(table.Type);
            });
        }