Esempio n. 1
0
        public static Dictionary <string, string>[] GetRows(bool useCache = true)
        {
            System.Runtime.Caching.ObjectCache cache = MemoryCache.Default;
            CacheItemPolicy policy = new CacheItemPolicy();

            policy.AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(1);

            if (useCache && cache["FWK_ConfigSettings"] != null)
            {
                return(cache["FWK_ConfigSettings"] as Dictionary <string, string>[]);
            }

            var result = new List <Dictionary <string, string> >();

            using (var conn = new SqlConnection(Jics))
            {
                const string scmd = "select * from [dbo].FWK_ConfigSettings;";
                using (var cmd = new SqlCommand(scmd, conn))
                {
                    conn.Open();
                    var r = cmd.ExecuteReader();

                    if (!r.HasRows)
                    {
                        throw new Exception("No data from FWK_ConfigSettings");
                    }

                    while (r.Read())
                    {
                        var row = new Dictionary <string, string>();
                        for (var i = 0; i < r.FieldCount; ++i)
                        {
                            row[r.GetName(i)] = r[i] as string;
                        }
                        result.Add(row);
                    }
                }
            }

            cache.Set("FWK_ConfigSettings", result.ToArray(), policy);
            return(cache["FWK_ConfigSettings"] as Dictionary <string, string>[]);
        }
Esempio n. 2
0
 protected CachingDecorator(System.Runtime.Caching.ObjectCache cache)
 {
     _cache = cache;
 }
Esempio n. 3
0
 public CachingWeatherService(IWeatherService decorated, System.Runtime.Caching.ObjectCache cache) : base(cache)
 {
     _decorated = decorated;
 }
Esempio n. 4
0
        /// <summary>
        /// full constructor
        /// </summary>
        /// <param name="region"></param>
        /// <param name="properties">cache configuration properties</param>
        /// <remarks>
        /// There are two (2) configurable parameters:
        /// <ul>
        ///		<li>expiration = number of seconds to wait before expiring each item</li>
        ///		<li>priority = a numeric cost of expiring each item, where 0 is Default and 1 is NotRemovable.</li>
        /// </ul>
        /// All parameters are optional. The defaults are an expiration of 300 seconds and the default priority of 0.
        /// </remarks>
        /// <exception cref="IndexOutOfRangeException">The "priority" property is between 0 and 1</exception>
        /// <exception cref="ArgumentException">The "expiration" property could not be parsed.</exception>
        public MemoryCache(string region, IDictionary<string, string> properties)
        {
            this.region = region;
            cache = System.Runtime.Caching.MemoryCache.Default;
            Configure(properties);

            rootCacheKey = GenerateRootCacheKey();
            StoreRootCacheKey();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SystemServiceCache"/> class.
 /// </summary>
 /// <param name="cache">The cache.</param>
 public SystemServiceCache(SystemCaching.ObjectCache cache)
 {
     Cache    = cache;
     Settings = new ServiceCacheSettings(new DefaultFileTouchableCacheItem(this, new DefaultTouchableCacheItem(this, null)));
 }
Esempio n. 6
0
 static SearchController()
 {
     _cache = new MemoryCache("SearchController.ContentSearchers");
 }