Ejemplo n.º 1
0
    public static string GetCompactedJavaScript()
    {
        List<string> scripts = new List<string>();
        foreach (string script in SiteUtility.Scripts)
        {
            scripts.Add(HttpContext.Current.Request.MapPath(script));
        }

        // set to expire cache when any of the source files changes
        CacheDependency cacheDependency = new CacheDependency(scripts.ToArray());

        Cache cache = HttpRuntime.Cache;
        string cacheKey = "CompactedJavaScript";
        if (cache[cacheKey] != null)
        {
            return cache[cacheKey] as string;
        }

        StringBuilder sb = new StringBuilder();
        sb.AppendLine("/*  Generated " + DateTime.Now.ToUniversalTime().ToString("R", DateTimeFormatInfo.InvariantInfo) + "  */\n");
        sb.AppendLine(FileProcessor.Run(PackMode.JSMin, scripts.ToArray(), false));

        string output = sb.ToString();

        // hold for 30 minutes
        cache.Insert(cacheKey, output, cacheDependency, DateTime.Now.AddMinutes(30),
            Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);

        return output;
    }
Ejemplo n.º 2
0
 public CacheDependency GetCacheDependencyInstance(HttpContext context) 
 {
     CacheDependency dependency = new CacheDependency(context.Server.MapPath("~/test.txt"));
     return dependency;
     //CacheDependency dependency = new CacheDependency(null, new string[1] { "key1" });
     //return dependency;
 }
Ejemplo n.º 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) {

            RegScript("scripts/jquery.org.js");
            string cacheKey = "ORG";
            OrgNode root = CacheManager.GetCache(cacheKey) as OrgNode;
            if (null == root) {
                string xmlpath = Server.MapPath("~/orgmap.xml");

                XElement xe = XElement.Load(xmlpath);
                root = new OrgNode {
                    Text = BuildText(xe) ,
                    Id = xe.Attribute("id").Value ,
                    Description = xe.Element("c").Value
                };
                var childs = from p in xe.Element("d").Elements("a")
                             select new OrgNode {
                                 Id = p.Attribute("id").Value ,
                                 Text = BuildText(p) ,
                                 Description = p.Element("c").Value
                             };
                foreach (var item in childs) {
                    root.Nodes.Add(item);
                }

                CacheDependency cdep = new CacheDependency(xmlpath);
                CacheManager.SetCache(cacheKey , root , cdep);
            }
            OrgChart1.Node = root;
        }
    }
 public AggregateCacheDependency GetAggregateDependency(HttpContext context)
 {
     CacheDependency dependency1 = new CacheDependency(context.Server.MapPath("~/test1.txt"));
     CacheDependency dependency2 = new CacheDependency(context.Server.MapPath("~/test2.txt"));
     CacheDependency dependency3 = new CacheDependency(null, new string[] {"key1"});
     AggregateCacheDependency aggDependency = new AggregateCacheDependency();
     aggDependency.Add(new CacheDependency[] {dependency1, dependency2, dependency3 });
     return aggDependency;
 }
Ejemplo n.º 5
0
    /// <summary>
    /// 
    /// </summary>
    /// <param name="key">Tên của cache</param>
    /// <param name="myobject">Đối tượng cần cache</param>
    /// <param name="priority">Ưu tiên</param>
    /// <param name="timeremoveifnotuse">Thời gian cache sẽ remove nếu không sử dụng, nếu gọi cache sẽ sẽ rebuild lại nếu không sử dụng đến</param>
    /// <param name="timeremovecache">Thời gian cache sẽ bị xóa tính từ thời gian bắt đầu tạo cache</param>
    public static void SetCacheFile(string key, DataSet myobject, System.Runtime.Caching.CacheItemPriority priority, int timeremoveifnotuse, int timeremovecache)
    {
        string filepath = HostingEnvironment.MapPath("~/_cache/" + key + ".xml");
        if (!File.Exists(filepath))
        {
            Folder.CreateFolder(HostingEnvironment.MapPath("~/_cache"));
        }
        else
            File.Delete(filepath);

        CacheDependency dependency = new CacheDependency(filepath);
        HttpContext.Current.Cache.Insert(key, myobject, dependency, DateTime.Now.AddDays(10), TimeSpan.Zero, CacheItemPriority.Default, null);
    }
Ejemplo n.º 6
0
 DataTable loadFromXMLOrCache()
 {
     DataTable tbl = (DataTable)Cache[cacheKey];
     if (null == tbl)
     {
         string xmlFile = Server.MapPath("~/app_data/orders.xml");
         tbl = new DataTable();
             tbl.ReadXml(xmlFile);
         CacheDependency dep = new CacheDependency(xmlFile);
         Cache.Insert(cacheKey, tbl, dep);
     }
     return tbl;
 }
Ejemplo n.º 7
0
 public Blog GetBlog(Int64 id)
 {
     var key = string.Format(BlogKey, id);
         var obj = CacheHelper.Get(key);
         if(obj == null)
         {
             var blog = BlogDal.SelectById(id);
             var mem = GetMember(blog.NguoiTao);
             var keys = new string[1];
             keys[0] = string.Format(MemKey, blog.NguoiTao);
             var dep = new CacheDependency(null, keys);
             CacheHelper.Max(key, blog, dep);
             obj = blog;
         }
         return (Blog)obj;
 }
Ejemplo n.º 8
0
 public List<Member> GetMembers()
 {
     var key = string.Format(MemKey, "List");
         var obj = CacheHelper.Get(key);
         if (obj == null)
         {
             var mems = MemberDal.SelectAll().Take(10).ToList();
             var listKey = new List<string>();
             mems.ForEach(x =>
                              {
                                  CacheHelper.Max(string.Format(MemKey, x.Id), x);
                                  listKey.Add(string.Format(MemKey, x.Id));
                              });
             var dep = new CacheDependency(null, listKey.ToArray());
             Cache.Insert(key, mems, dep);
             obj = mems;
         }
         return (List<Member>)obj;
 }
Ejemplo n.º 9
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //Ao carregar a página pela 1 vez
        if (!Page.IsPostBack)
        {
            //Armazenei o caminho fisico do arquivo com o nome ARQUIVO.txt
            String CaminhoArquivo = Server.MapPath("") + @"\Arquivo.txt";

            //Classe responsável por fazer o acesso ao arquivo
            StreamReader Leitor = new StreamReader(CaminhoArquivo);

            //Abri o arquivo e armazenei o seu conteúdo na variável Conteudo
            String Conteudo = Leitor.ReadToEnd();
            Leitor.Close();

            //Classe responsável por criar uma dependência ao arquivo
            CacheDependency Dependencia = new CacheDependency(CaminhoArquivo);

            //Inseri o conteúdo do arquivo no cache
            Cache.Insert("ARQUIVO", Conteudo, Dependencia);
        }
    }
Ejemplo n.º 10
0
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!this.IsPostBack)
		{
			lblInfo.Text += "Creating dependent item...<br>";
			Cache.Remove("Dependent");
			System.Web.Caching.CacheDependency dep1 =
			 new System.Web.Caching.CacheDependency(Server.MapPath("dependency.txt"));
			System.Web.Caching.CacheDependency dep2 =
			 new System.Web.Caching.CacheDependency(Server.MapPath("dependency2.txt"));


			// Create the aggregate.
			CacheDependency[] dependencies = new CacheDependency[] { dep1, dep2 };
			AggregateCacheDependency aggregateDep = new AggregateCacheDependency();
			aggregateDep.Add(dependencies);

			string item = "Dependent cached item";
			lblInfo.Text += "Adding dependent item<br>";
			Cache.Insert("Dependent", item, aggregateDep);
		}
	}
Ejemplo n.º 11
0
 protected void Page_Load(object sender, EventArgs e)
 {
     //首先从Cache中获取Dataset
     DataSet productds = (DataSet)Cache["Products"];
     //如果Cache中不存在DataSet,则从数据库中获取DataSet,并添加到缓存中
     if (productds == null)
     {
         productds = GetProductDataSet();
         //Cache.Insert("Products", productds);
         //该对象将在1小时后失效,这里使用了绝对到期时间
         //Cache.Insert("Products", productds, null, DateTime.Now.AddHours(1),System.Web.Caching.Cache.NoSlidingExpiration);
         //使用可调日期,在最后一次访问1小时候缓存过期
        // Cache.Insert("Products", productds, null,
         //    System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromHours(1));
         //创建一个基于web.config配置文件的依赖,当该文件发生变化时,则从缓存中移除缓存项。
         CacheDependency cd = new CacheDependency(Server.MapPath("web.config"));
         //在Insert中指定该依赖项,并且指定缓存的优先级为高优先级
         Cache.Insert("Products", productds, cd, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromHours(1),CacheItemPriority.High,null);
     }
     GridView1.DataSource = productds;
     GridView1.DataMember = "productsTable";
     GridView1.DataBind();
 }
Ejemplo n.º 12
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //Ao carregar a página pela 1 vez
        if (!Page.IsPostBack)
        {
        //if (Cache["ARQUIVOS"] != null)
        //{
            //Armazenei o caminho fisico do arquivo com o nome ARQUIVO.xml
            String CaminhoArquivo = Server.MapPath("") + @"\Arquivo.xml";

            //Classe responsável por fazer o acesso ao arquivo
            XmlDocument Leitor = new XmlDocument();
            Leitor.Load(CaminhoArquivo);

            //Abri e armazenei o seu conteúdo do xml
            String ConteudoXml = Leitor.OuterXml;

            //Classe responsável por criar uma dependência ao arquivo
            CacheDependency Dependencia = new CacheDependency(CaminhoArquivo);

            //Inseri o conteúdo do arquivo no cache
            Cache.Insert("CONTEUDO", ConteudoXml, Dependencia);
        }
    }
Ejemplo n.º 13
0
 /// <summary>
 /// 把对象加载到Cache,附加缓存依赖信息
 /// </summary>
 /// <param name="key">键</param>
 /// <param name="obj">对象</param>
 /// <param name="dep">缓存依赖</param>
 public static void Insert(string key, object obj, CacheDependency dep)
 {
     Insert(key, obj, dep, MinuteFactor * 3);
 }
Ejemplo n.º 14
0
 public static void Set(string key, object val, CacheDependency dependency)
 {
     _cache.Insert(key, val, dependency);
 }
Ejemplo n.º 15
0
    public SysSet loadCacheConfig(string configFilePath)
    {
        SysSet Cache_SysSet = HttpContext.Current.Cache["Cache_SysSet"] as SysSet;
            if (Cache_SysSet == null)
            {
                //创建缓存依赖项
                CacheDependency dependency = new CacheDependency(configFilePath);
                //创建缓存
                HttpContext.Current.Cache.Add("Cache_SysSet", loadConfig(configFilePath), dependency, Cache.NoAbsoluteExpiration, new TimeSpan(0, 30, 0), CacheItemPriority.Default, null);
                Cache_SysSet = HttpContext.Current.Cache["Cache_Webset"] as SysSet;
            }

            return Cache_SysSet;
    }
Ejemplo n.º 16
0
 public void Insert(string key, object value, CacheDependency dependencies)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 17
0
 public static void Insert(string key, object obj, CacheDependency dep, int seconds, CacheItemPriority priority)
 {
     if (obj != null)
         {
             _cache.Insert(key, obj, dep, DateTime.Now.AddSeconds(Factor * seconds), TimeSpan.Zero, priority, null);
         }
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Adds the specified item to the cache.
 /// </summary>
 /// <param name="key">The cache key used to reference the item. It will be prefixed with the current blog instance's id.</param>
 /// <param name="value">The item to be added to the cache.</param>
 /// <param name="dependencies">The file or cache key dependencies for the item. When any dependency changes, the object becomes invalid and is removed from the cache. If there are no dependencies, this parameter contains null.</param>
 /// <param name="absoluteExpiration">The time at which the added object expires and is removed from the cache. If you are using sliding expiration, the absoluteExpiration parameter must be System.Web.Caching.Cache.NoAbsoluteExpiration.</param>
 /// <param name="slidingExpiration">The interval between the time the added object was last accessed and the time at which that object expires. If this value is the equivalent of 20 minutes, the object expires and is removed from the cache 20 minutes after it is last accessed. If you are using absolute expiration, the slidingExpiration parameter must be System.Web.Caching.Cache.NoSlidingExpiration.</param>
 /// <param name="priority">The relative cost of the object, as expressed by the System.Web.Caching.CacheItemPriority enumeration. The cache uses this value when it evicts objects; objects with a lower cost are removed from the cache before objects with a higher cost.</param>
 /// <param name="onRemoveCallback">A delegate that, if provided, is called when an object is removed from the cache. You can use this to notify applications when their objects are deleted from the cache.</param>
 /// <returns>An object that represents the item that was added if the item was previously stored in the cache; otherwise, null.</returns>
 public override object Add(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback)
 {
     return(_cache.Add(_keyPrefix + key, value, dependencies, absoluteExpiration, slidingExpiration, priority, onRemoveCallback));
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Inserts an object into the cache with dependencies and expiration policies.
 /// </summary>
 /// <param name="key">The cache key used to reference the item. It will be prefixed with the current blog instance's id.</param>
 /// <param name="value">The object to be inserted into the cache.</param>
 /// <param name="dependencies">The file or cache key dependencies for the inserted object. When any dependency changes, the object becomes invalid and is removed from the cache. If there are no dependencies, this parameter contains null.</param>
 /// <param name="absoluteExpiration">The time at which the added object expires and is removed from the cache. If you are using sliding expiration, the absoluteExpiration parameter must be System.Web.Caching.Cache.NoAbsoluteExpiration.</param>
 /// <param name="slidingExpiration">The interval between the time the added object was last accessed and the time at which that object expires. If this value is the equivalent of 20 minutes, the object expires and is removed from the cache 20 minutes after it is last accessed. If you are using absolute expiration, the slidingExpiration parameter must be System.Web.Caching.Cache.NoSlidingExpiration.</param>
 public override void Insert(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration)
 {
     _cache.Insert(_keyPrefix + key, value, dependencies, absoluteExpiration, slidingExpiration);
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Inserts an object into the cache that has file or key dependencies.
 /// </summary>
 /// <param name="key">The cache key used to reference the item. It will be prefixed with the current blog instance's id.</param>
 /// <param name="value">The object to be inserted into the cache.</param>
 /// <param name="dependencies">The file or cache key dependencies for the inserted object. When any dependency changes, the object becomes invalid and is removed from the cache. If there are no dependencies, this parameter contains null.</param>
 public override void Insert(string key, object value, CacheDependency dependencies)
 {
     _cache.Insert(_keyPrefix + key, value, dependencies);
 }
Ejemplo n.º 21
0
        private static void OnCacheItemRemoved(string key, CacheItemUpdateReason reason, out object obj, out CacheDependency dependency, out DateTime absoluteExpiration, out TimeSpan slidingExpiration)
        {
            var uploadSession = GetSession(key);

            CoreContext.TenantManager.SetCurrentTenant(uploadSession.TenantId);

            using (var dao = Global.DaoFactory.GetFileDao())
            {
                dao.AbortUploadSession(uploadSession);
            }

            obj                = null;
            dependency         = null;
            absoluteExpiration = AbsoluteExpiration;
            slidingExpiration  = SlidingExpiration;
        }
Ejemplo n.º 22
0
        public static void InsertTypeFileDep(Type type, string filename)
        {
            CacheDependency dep = new CacheDependency(filename);

            HttpRuntime.Cache.Insert(cacheTypePrefix + filename, type, dep);
        }
Ejemplo n.º 23
0
        public static void InsertOutputIntoCache(double absoluteExpiration, double slidingExpiration, string cacheKey, object output, CacheDependency cacheDependency, CacheItemPriority priority)
        {
            // -1 means it comes from web config
            var absBase     = absoluteExpiration == -1 ? Configuration.Cache.AbsoluteExpirationSeconds : absoluteExpiration;
            var slidingBase = slidingExpiration == -1 ? Configuration.Cache.SlidingExpirationSeconds : slidingExpiration;

            // 0 means no caching
            var abs     = absBase == 0 ? Cache.NoAbsoluteExpiration : DateTime.UtcNow.AddSeconds((double)absBase);
            var sliding = slidingBase == 0 ? Cache.NoSlidingExpiration : TimeSpan.FromSeconds((double)slidingBase);

            if (abs != Cache.NoAbsoluteExpiration && sliding != Cache.NoSlidingExpiration)
            {
                sliding = Cache.NoSlidingExpiration;
            }

            DistributedApplication.Cache.Insert(cacheKey, output, cacheDependency, abs, sliding, priority, null);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// 设置某缓存的值和跟踪缓存依赖项。
        /// </summary>
        /// <param name="CacheKey">缓存的键</param>
        /// <param name="objObject">缓存的值</param>
        /// <param name="objDependency">缓存依赖项</param>
        /// <param name="AbsoluteExpiration">缓存移出的时间</param>
        /// <param name="SlidingExpiration">缓存的有效期时间长度</param>
        public static void SetCache(string CacheKey, object objObject, CacheDependency objDependency, DateTime AbsoluteExpiration, TimeSpan SlidingExpiration)
        {
            Cache objCache = HttpRuntime.Cache;

            objCache.Insert(CacheKey, objObject, objDependency, AbsoluteExpiration, SlidingExpiration);
        }
Ejemplo n.º 25
0
 public static void Insert(string key, object obj, CacheDependency dep)
 {
     Insert(key, obj, dep, HourFactor * 12);
 }
Ejemplo n.º 26
0
        /// <internalonly/>
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        protected internal override void Render(HtmlTextWriter output)
        {
            CacheDependency sqlCacheDep = null;

            // If the output is cached, use it and do nothing else
            if (_outputString != null)
            {
                output.Write(_outputString);
                RegisterValidationEvents();
                return;
            }

            // If caching was turned off, just render the control
            if (_cachingDisabled || !RuntimeConfig.GetAppConfig().OutputCache.EnableFragmentCache)
            {
                _cachedCtrl.RenderControl(output);
                return;
            }

            // Create SQL cache dependency before we render the page
            if (_sqlDependency != null)
            {
                sqlCacheDep = SqlCacheDependency.CreateOutputCacheDependency(_sqlDependency);
            }

            _cacheEntry.CssStyleString = GetCssStyleRenderString(output.GetType());

            // Create a new HtmlTextWriter, with the same type as the current one (see ASURT 118922)
            StringWriter    tmpWriter     = new StringWriter();
            HtmlTextWriter  tmpHtmlWriter = Page.CreateHtmlTextWriterFromType(tmpWriter, output.GetType());
            CacheDependency cacheDep;
            TextWriter      savedWriter = Context.Response.SwitchWriter(tmpWriter);

            try {
                // Make sure the Page knows about us while the control's OnPreRender is called
                Page.PushCachingControl(this);
                _cachedCtrl.RenderControl(tmpHtmlWriter);
                Page.PopCachingControl();
            }
            finally {
                Context.Response.SwitchWriter(savedWriter);
            }

            _cacheEntry.OutputString = tmpWriter.ToString();

            // Send the output to the response
            output.Write(_cacheEntry.OutputString);

            // Cache the output

            cacheDep = _cacheDependency;

            if (sqlCacheDep != null)
            {
                if (cacheDep == null)
                {
                    cacheDep = sqlCacheDep;
                }
                else
                {
                    AggregateCacheDependency aggr = new AggregateCacheDependency();

                    aggr.Add(cacheDep);
                    aggr.Add(sqlCacheDep);
                    cacheDep = aggr;
                }
            }

            ControlCachedVary cachedVary = null;
            string            realItemCacheKey;

            // If there are no varies, use the non-varying key
            if (_varyByParamsCollection == null && _varyByControlsCollection == null && _varyByCustom == null)
            {
                realItemCacheKey = _cacheKey;
            }
            else
            {
                string[] varyByParams = null;
                if (_varyByParamsCollection != null)
                {
                    varyByParams = _varyByParamsCollection.GetParams();
                }

                cachedVary = new ControlCachedVary(varyByParams, _varyByControlsCollection, _varyByCustom);

                HashCodeCombiner combinedHashCode = new HashCodeCombiner(_nonVaryHashCode);
                realItemCacheKey = ComputeVaryCacheKey(combinedHashCode, cachedVary);
            }

            // Compute the correct expiration, sliding or absolute
            DateTime utcExpirationTime;
            TimeSpan slidingExpiration;

            if (_useSlidingExpiration)
            {
                utcExpirationTime = Cache.NoAbsoluteExpiration;
                slidingExpiration = _utcExpirationTime - DateTime.UtcNow;
            }
            else
            {
                utcExpirationTime = _utcExpirationTime;
                slidingExpiration = Cache.NoSlidingExpiration;
            }

            try {
                OutputCache.InsertFragment(_cacheKey, cachedVary,
                                           realItemCacheKey, _cacheEntry,
                                           cacheDep /*dependencies*/,
                                           utcExpirationTime, slidingExpiration,
                                           _provider);
            }
            catch {
                if (cacheDep != null)
                {
                    cacheDep.Dispose();
                }
                throw;
            }
        }
Ejemplo n.º 27
0
 public virtual void Insert(string CacheKey, object objObject, CacheDependency objDependency, System.DateTime AbsoluteExpiration, System.TimeSpan SlidingExpiration)
 {
     Insert(CacheKey, objObject, objDependency, AbsoluteExpiration, SlidingExpiration, CacheItemPriority.Default, null);
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DNNCacheDependency"/> class.
 /// </summary>
 /// <param name="systemCacheDependency">The system cache dependency.</param>
 public DNNCacheDependency(CacheDependency systemCacheDependency)
 {
     _systemCacheDependency = systemCacheDependency;
 }
	public void Insert(string key, object value, CacheDependency dependencies, System.DateTime absoluteExpiration, System.TimeSpan slidingExpiration) {}
Ejemplo n.º 30
0
 /// <summary>
 /// 缓存实例插入(缓存过期时间是一天)
 /// </summary>
 /// <param name="key">缓存实例名称</param>
 /// <param name="obj">要缓存的对象</param>
 /// <param name="dep">缓存的依赖项</param>
 public static void Insert(string key, object obj, CacheDependency dep)
 {
     Insert(key, obj, dep, Hourfactor * 12);
 }
Ejemplo n.º 31
0
 public void Insert(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 32
0
        /// <summary>
        /// 缓存实例插入(缓存过期时间是一天)
        /// </summary>
        /// <param name="key">缓存实例名称</param>
        /// <param name="obj">要缓存的对象</param>
        /// <param name="xmlPath">缓存的依赖项xml文件的路径(绝对路径)</param>
        public static void Insert(string key, object obj, string xmlPath)
        {
            var dep = new CacheDependency(xmlPath);

            Insert(key, obj, dep, Hourfactor * 12);
        }
Ejemplo n.º 33
0
        /// <summary>
        /// 设置某缓存的值和跟踪缓存依赖项。
        /// </summary>
        /// <param name="CacheKey">缓存的键</param>
        /// <param name="objObject">缓存的值</param>
        /// <param name="objDependency">缓存依赖项</param>
        public static void SetCache(string CacheKey, object objObject, CacheDependency objDependency)
        {
            Cache objCache = HttpRuntime.Cache;

            objCache.Insert(CacheKey, objObject, objDependency);
        }
Ejemplo n.º 34
0
 /// <summary>
 /// 缓存实例插入
 /// </summary>
 /// <param name="key">用于引用该对象的缓存键</param>
 /// <param name="obj">要插入缓存中的对象</param>
 /// <param name="dep">该项的文件依赖项或缓存键依赖项。当任何依赖项更改时,该对象即无效,并从缓存中移除。如果没有依赖项,则此参数包含空引用(Visual Basic 中为 Nothing)</param>
 /// <param name="seconds">所插入对象将过期并被从缓存中移除的时间。</param>
 public static void Insert(string key, object obj, CacheDependency dep, int seconds)
 {
     Insert(key, obj, dep, seconds, CacheItemPriority.Normal);
 }
Ejemplo n.º 35
0
 public static void Set(string key, object val, CacheDependency dependency, DateTime absoluteExpiration, TimeSpan slidingExpiration)
 {
     _cache.Insert(key, val, dependency, absoluteExpiration, slidingExpiration);
 }
Ejemplo n.º 36
0
        /// <summary>
        /// 缓存实例插入
        /// </summary>
        /// <param name="key">用于引用该对象的缓存键</param>
        /// <param name="obj">要插入缓存中的对象</param>
        /// <param name="xmlPath">缓存的依赖项xml文件的路径(绝对路径)</param>
        /// <param name="seconds">所插入对象将过期并被从缓存中移除的时间。</param>
        public static void Insert(string key, object obj, string xmlPath, int seconds)
        {
            var dep = new CacheDependency(xmlPath);

            Insert(key, obj, dep, seconds, CacheItemPriority.Normal);
        }
Ejemplo n.º 37
0
 /// <summary>
 /// 插入持久性缓存,附加缓存依赖
 /// </summary>
 /// <param name="key">键值</param>
 /// <param name="obj">对象</param>
 /// <param name="dep">缓存依赖</param>
 public static void Permanent(string key, object obj, CacheDependency dep)
 {
     if (obj != null)
     {
         _cache.Insert(key, obj, dep, DateTime.MaxValue, TimeSpan.Zero, CacheItemPriority.NotRemovable, null);
     }
 }
Ejemplo n.º 38
0
        /// <summary>
        /// 缓存实例插入(默认缓存20分钟)
        /// </summary>
        /// <param name="key">缓存实例名称</param>
        /// <param name="obj">要缓存的对象</param>
        public static void Insert(string key, object obj)
        {
            CacheDependency dep = null;

            Insert(key, obj, dep, 20);
        }
Ejemplo n.º 39
0
 /// <summary>
 /// 设置缓存
 /// </summary>
 /// <param name="key">键</param>
 /// <param name="value">值</param>
 /// <param name="cacheDependency">
 /// 所插入对象的文件依赖项或缓存键依赖项。当任何依赖项更改时,该对象即无效,并从缓存中移除。如果没有依赖项,则此参数包含 nullNothingnullptrnull 引用。
 /// </param>
 public static void Set(string key, object value, CacheDependency cacheDependency)
 {
     Cache.Insert(AppPrefix + key, value, cacheDependency);
 }
Ejemplo n.º 40
0
        /// <summary>
        /// 缓存实例插入
        /// </summary>
        /// <param name="key">缓存实例名称</param>
        /// <param name="obj">要缓存的对象</param>
        /// <param name="seconds">缓存的时间</param>
        public static void Insert(string key, object obj, int seconds)
        {
            CacheDependency dep = null;

            Insert(key, obj, dep, seconds);
        }
Ejemplo n.º 41
0
 public static void Max(string key, object obj, CacheDependency dep)
 {
     if (obj != null)
         {
             _cache.Insert(key, obj, dep, DateTime.MaxValue, TimeSpan.Zero, CacheItemPriority.AboveNormal, null);
         }
 }
Ejemplo n.º 42
0
 /// <summary>
 /// 插入缓存
 /// </summary>
 /// <param name="key">用于引用项的缓存密钥</param>
 /// <param name="value">要插入到缓存的对象</param>
 /// <param name="dependencies">文件或缓存关键的依存关系所插入对象。 当任何依赖关系更改时,该对象将变为无效,并从缓存中删除。 如果没有依赖关系,此参数包含 null</param>
 public static void Insert(string key, object value, CacheDependency dependencies)
 {
     _cache.Insert(key, value, dependencies);
 }
Ejemplo n.º 43
0
 public static void Insert(string key, object obj, CacheDependency dep, int seconds)
 {
     Insert(key, obj, dep, seconds, CacheItemPriority.Normal);
 }
Ejemplo n.º 44
0
 /// <summary>
 /// 插入缓存
 /// </summary>
 /// <param name="key">用于引用该对象的缓存密钥</param>
 /// <param name="value">要插入到缓存的对象</param>
 /// <param name="dependencies">文件或缓存关键的依存关系所插入对象。 当任何依赖关系更改时,该对象将变为无效,并从缓存中删除。 如果没有依赖关系,此参数包含 null</param>
 /// <param name="absoluteExpiration">从该处插入的对象过期并从缓存中删除的时间。 若要避免的本地时间,如从标准时间到夏时制的更改可能存在的问题,请使用 System.DateTime.UtcNow,而不是 System.DateTime.Now 为此参数值。 如果您使用的绝对过期 slidingExpiration 参数必须是 System.Web.Caching.Cache.NoSlidingExpiration</param>
 /// <param name="slidingExpiration">对象的到期时间和上次访问所插入的对象的时间之间的间隔。 如果此值为 20 分钟的等效项,该对象会过期,可从缓存中删除上次访问后的 20 分钟。 如果您使用可调到期,absoluteExpiration 参数必须是 System.Web.Caching.Cache.NoAbsoluteExpiration</param>
 /// <param name="onUpdateCallback">从缓存中删除该对象之前将调用一个委托。 您可以用于更新缓存的项目,并确保它不删除从缓存</param>
 public static void Insert(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemUpdateCallback onUpdateCallback)
 {
     _cache.Insert(key, value, dependencies, absoluteExpiration, slidingExpiration, onUpdateCallback);
 }
Ejemplo n.º 45
0
 public virtual void Insert(string CacheKey, object objObject, CacheDependency objDependency)
 {
     Insert(CacheKey, objObject, objDependency, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, CacheItemPriority.Default, null);
 }
Ejemplo n.º 46
0
 /// <summary>
 /// 插入缓存
 /// </summary>
 /// <param name="key">用于引用该对象的缓存密钥</param>
 /// <param name="value">要插入到缓存的对象</param>
 /// <param name="dependencies">文件或缓存关键的依存关系所插入对象。 当任何依赖关系更改时,该对象将变为无效,并从缓存中删除。 如果没有依赖关系,此参数包含 null</param>
 /// <param name="absoluteExpiration">从该处插入的对象过期并从缓存中删除的时间。 若要避免的本地时间,如从标准时间到夏时制的更改可能存在的问题,请使用 System.DateTime.UtcNow,而不是 System.DateTime.Now 为此参数值。 如果您使用的绝对过期 slidingExpiration 参数必须是 System.Web.Caching.Cache.NoSlidingExpiration</param>
 /// <param name="slidingExpiration">对象的到期时间和上次访问所插入的对象的时间之间的间隔。 如果此值为 20 分钟的等效项,该对象会过期,可从缓存中删除上次访问后的 20 分钟。 如果您使用可调到期,absoluteExpiration 参数必须是 System.Web.Caching.Cache.NoAbsoluteExpiration</param>
 /// <param name="priority">与存储在缓存中,如通过所表示的其他项相关对象的成本 System.Web.Caching.CacheItemPriority 枚举。 逐出对象; 时,缓存使用此值具有较低的成本的对象会从缓存后再成本较高的对象</param>
 /// <param name="onRemoveCallback">从缓存中删除该对象之前将调用一个委托。 您可以用于更新缓存的项目,并确保它不删除从缓存</param>
 public static void Insert(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback)
 {
     _cache.Insert(key, value, dependencies, absoluteExpiration, slidingExpiration, priority, onRemoveCallback);
 }
Ejemplo n.º 47
0
 public virtual void Insert(string CacheKey, object Value, CacheDependency objDependency, System.DateTime AbsoluteExpiration, System.TimeSpan SlidingExpiration, CacheItemPriority Priority, CacheItemRemovedCallback OnRemoveCallback)
 {
     if (objDependency == null)
     {
         Cache.Insert(CacheKey, Value, null, AbsoluteExpiration, SlidingExpiration, Priority, OnRemoveCallback);
     }
     else
     {
         Cache.Insert(CacheKey, Value, objDependency.SystemCacheDependency, AbsoluteExpiration, SlidingExpiration, Priority, OnRemoveCallback);
     }
 }
Ejemplo n.º 48
0
        /// <summary>
        /// 设置 Cache 值
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="cacheValue">Cache 值</param>
        /// <param name="time">持续时间(以分钟为单位)</param>
        public static void SetCache(string key, object value, int time)
        {
            CacheDependency cacheDependency = new CacheDependency(Path.GetTempFileName());

            HttpContext.Current.Cache.Insert(key, value, cacheDependency, DateTime.Now.AddMinutes(time), TimeSpan.Zero);
        }
	public void Insert(string key, object value, CacheDependency dependencies) {}
Ejemplo n.º 50
0
        /// <summary>
        /// 插入缓存.
        /// </summary>
        /// <param name="key">key</param>
        /// <param name="value">value</param>
        /// <param name="cacheDurationInSeconds">过期时间单位秒</param>
        /// <param name="priority">缓存项属性</param>
        private void Add <V>(string key, V value, int cacheDurationInSeconds, CacheDependency dependency, CacheItemPriority priority)
        {
            string keyString = key;

            HttpRuntime.Cache.Insert(keyString, value, dependency, DateTime.Now.AddSeconds(cacheDurationInSeconds), Cache.NoSlidingExpiration, priority, null);
        }
	public object Add(string key, object value, CacheDependency dependencies, System.DateTime absoluteExpiration, System.TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback) {}
Ejemplo n.º 52
0
 /// <summary>
 /// 设置缓存
 /// </summary>
 /// <param name="key">键</param>
 /// <param name="value">值</param>
 /// <param name="cacheDependency">
 /// 所插入对象的文件依赖项或缓存键依赖项。当任何依赖项更改时,该对象即无效,并从缓存中移除。如果没有依赖项,则此参数包含 nullNothingnullptrnull 引用
 /// </param>
 /// <param name="dt">
 /// 所插入对象将过期并被从缓存中移除的时间。若要避免可能出现的本地时间方面的问题(如从标准时间更改为夏时制),请对此参数值使用 UtcNow,不要使用 Now。如果使用绝对过期,则
 /// slidingExpiration 参数必须为 NoSlidingExpiration
 /// </param>
 /// <param name="ts">
 /// 最后一次访问所插入对象时与该对象过期时之间的时间间隔。如果该值等效于 20 分钟,则对象在最后一次被访问 20 分钟之后将过期并被从缓存中移除。如果使用可调过期,则
 /// absoluteExpiration 参数必须为 NoAbsoluteExpiration。
 /// </param>
 public static void Set(string key, object value, CacheDependency cacheDependency, DateTime dt, TimeSpan ts)
 {
     Cache.Insert(AppPrefix + key, value, cacheDependency, dt, ts);
 }
Ejemplo n.º 53
0
 public void Insert(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 54
0
 /// <summary>
 /// 设置缓存
 /// </summary>
 /// <param name="key">键</param>
 /// <param name="value">值</param>
 /// <param name="cacheDependency">
 /// 所插入对象的文件依赖项或缓存键依赖项。当任何依赖项更改时,该对象即无效,并从缓存中移除。如果没有依赖项,则此参数包含 nullNothingnullptrnull 引用
 /// </param>
 /// <param name="ts">
 /// 最后一次访问所插入对象时与该对象过期时之间的时间间隔。如果该值等效于 20 分钟,则对象在最后一次被访问 20 分钟之后将过期并被从缓存中移除。如果使用可调过期,则
 /// absoluteExpiration 参数必须为 NoAbsoluteExpiration。
 /// </param>
 public static void Set(string key, object value, CacheDependency cacheDependency, TimeSpan ts)
 {
     Cache.Insert(AppPrefix + key, value, cacheDependency, Cache.NoAbsoluteExpiration, ts);
 }
 //页面加载时,将DataSet插入到委托中去。
 protected void Page_Load(object sender, EventArgs e)
 {
     //首先从Cache中获取Dataset
     DataSet productds = (DataSet)Cache["Products"];
     //如果Cache中不存在DataSet,则从数据库中获取DataSet,并添加到缓存中
     if (productds == null)
     {
         productds = GetProductDataSet();
         //创建委托实例
         onRemove = new CacheItemRemovedCallback(this.RemovedCallback);
        //创建一个基于web.config配置文件的依赖,当该文件发生变化时,则从缓存中移除缓存项。
         CacheDependency cd = new CacheDependency(Server.MapPath("web.config"));
         //在Insert中指定该依赖项,并且指定缓存的优先级为高优先级,传递一个传托。
         Cache.Insert("Products", productds, cd, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromHours(1), CacheItemPriority.High,onRemove);
     }
     GridView1.DataSource = productds;
     GridView1.DataMember = "productsTable";
     GridView1.DataBind();
 }
Ejemplo n.º 56
0
 public object Add(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback)
 {
     return(HttpRuntime.Cache.Add(key, value, dependencies, absoluteExpiration, slidingExpiration, priority, onRemoveCallback));
 }
	// Methods
	public void Add(CacheDependency[] dependencies) {}
Ejemplo n.º 58
0
 /// <summary>
 /// 设置缓存
 /// </summary>
 /// <param name="key">键</param>
 /// <param name="value">值</param>
 /// <param name="cacheDependency">
 /// 该项的文件依赖项或缓存键依赖项。当任何依赖项更改时,该对象即无效,并从缓存中移除。如果没有依赖项,则此参数包含 null。
 /// </param>
 /// <param name="absoluteExpiration">
 /// 所插入对象将过期并被从缓存中移除的时间。若要避免可能出现的本地时间方面的问题(如从标准时间更改为夏时制),请对此参数值使用 UtcNow,不要使用 Now。如果使用绝对过期,则
 /// slidingExpiration 参数必须为 NoSlidingExpiration
 /// </param>
 /// <param name="slidingExpiration">
 /// 最后一次访问所插入对象时与该对象到期时之间的时间间隔。如果该值等效于 20 分钟,则对象在最后一次被访问 20 分钟之后将到期并被从缓存中移除。如果使用可调到期,则
 /// absoluteExpiration 参数必须为 NoAbsoluteExpiration。
 /// </param>
 /// <param name="priority">优先级</param>
 /// <param name="onUpdate">在从缓存中移除对象时将调用的委托(如果提供)。当从缓存中删除应用程序的对象时,可使用它来通知应用程序。</param>
 public static void Set(string key, object value, CacheDependency cacheDependency, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onUpdate)
 {
     Cache.Insert(AppPrefix + key, value, cacheDependency, absoluteExpiration, slidingExpiration, priority, onUpdate);
 }
Ejemplo n.º 59
0
 public object Add(string key, object value, CacheDependency dependencies)
 {
     return(Add(key, value, dependencies, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, CacheItemPriority.Default, null));
 }
Ejemplo n.º 60
0
 public object Add(string key, object value, CacheDependency dependencies, TimeSpan slidingExpiration, CacheItemRemovedCallback onRemoveCallback)
 {
     return(Add(key, value, dependencies, System.Web.Caching.Cache.NoAbsoluteExpiration, slidingExpiration, CacheItemPriority.Default, onRemoveCallback));
 }