コード例 #1
0
    public void SetMyObject(string key, MyObject myobj)
    {
        string cacheKey = this.GetFullCacheKey(key);

        if (null != myobj)
        {
            if (null == System.Web.HttpRuntime.Cache[cacheKey])
            {
                /* not shown...custom configuration to house the setting */
                CachingSettingsConfigurationSection settings = CachingSettingsConfigurationRetriever.GetCachingSettings();
                System.Web.HttpRuntime.Cache.Insert(
                    cacheKey,
                    myobj,
                    null,
                    System.Web.Caching.Cache.NoAbsoluteExpiration,
                    new TimeSpan(0, settings.MyObjectCacheMinutes, 0),
                    System.Web.Caching.CacheItemPriority.NotRemovable,
                    null);
            }
            else
            {
                System.Web.HttpRuntime.Cache[cacheKey] = myobj;
            }
        }
    }
コード例 #2
0
    public void SetMyObject(string key, MyObject myobj)
    {
        /* not shown...custom configuration to house the setting */
        CachingSettingsConfigurationSection settings = CachingSettingsConfigurationRetriever.GetCachingSettings();
        ObjectCache     cache  = MemoryCache.Default;
        CacheItemPolicy policy = new CacheItemPolicy {
            SlidingExpiration = new TimeSpan(0, settings.MyObjectCacheMinutes, 0), Priority = CacheItemPriority.NotRemovable
        };

        cache.Set(this.GetFullCacheKey(key), myobj, policy);
    }