Java Ehcache缓存的timeToIdleSeconds和timeToLiveSeconds区别(java使用cache缓存)

  本篇文章为你整理了Java Ehcache缓存的timeToIdleSeconds和timeToLiveSeconds区别(java使用cache缓存)的详细内容,包含有ehcache和本地缓存的区别 java使用cache缓存 cachetimeout java cachedthreadpool Java Ehcache缓存的timeToIdleSeconds和timeToLiveSeconds区别,希望能帮助你了解 Java Ehcache缓存的timeToIdleSeconds和timeToLiveSeconds区别。

   These are three cache attributes that can be used to build an effective eviction configuration.

   It is advised totest and tune these values to help optimize cache performance.

   TTI timeToIdleSeconds is the maximumnumber of seconds that an element can exist in the cache without being accessed,

   while TTLtimeToLiveSeconds is the maximum number of seconds that an element can exist in the cache whetheror not is has been accessed.

   If the eternal flag is set, elements are allowed to exist in the cache eternallyand none are evicted.

   The eternal setting overrides any TTI or TTL settings. These attributes are set for theentire cache in the configuration file. If you want to set them per element, you must do it programmatically

  

   中文翻译:

  

  

   1.TTI timeToIdleSeconds is the maximum number of seconds that an element can exist in the cache without being accessed:

   TTI用于设置对象在cache中的最大闲置时间,就是 在一直不访问这个对象的前提下,这个对象可以在cache中的存活时间。

   2.TTL timeToLiveSeconds is the maximum number of seconds that an element can exist in the cache whether

   or not is has been accessed.

   TTL用于设置对象在cache中的最大存活时间,就是 无论对象访问或是不访问(闲置),这个对象在cache中的存活时间。

   3.If the eternal flag is set, elements are allowed to exist in the cache eternallyand none are evicted。

   当配置了 eternal ,那么TTI和TTL这两个配置将被覆盖,对象会永恒存在cache中,永远不会过期。

  

   给出一个ehcache.xml配置事例:

   ehcache xmlns:xsi= http://www.w3.org/2001/XMLSchema-instance xsi:noNamespaceSchemaLocation= ehcache.xsd

   diskStore path= java.io.tmpdir /

   defaultCache maxElementsInMemory= 10000 eternal= false timeToIdleSeconds= 600 overflowToDisk= false

   /defaultCache

   cache name= cache maxElementsInMemory= 1000 eternal= false timeToIdleSeconds= 43200 timeToLiveSeconds= 43200 overflowToDisk= false memoryStoreEvictionPolicy= LRU /

   /ehcache

  

   给大家解释一下上面配置信息:

   name:缓存名称。
 

   maxElementsInMemory:缓存最大个数。
 

   eternal:对象是否永久有效,一但设置了,timeout将不起作用。
 

   timeToIdleSeconds:设置对象在失效前的允许闲置时间(单位:秒)。仅当eternal=false对象不是永久有效时使用,可选属性,默认值是0,也就是可闲置时间无穷大。
 

   可理解为: TTI用于设置对象在cache中的最大闲置时间,就是 在一直不访问这个对象的前提下,这个对象可以在cache中的存活时间。
 

  
 

   timeToLiveSeconds:设置对象在失效前允许存活时间(单位:秒)。最大时间介于创建时间和失效时间之间。仅当eternal=false对象不是永久有效时使用,默认是0.,也就是对象存活时间无穷大。
 

   可理解为: TTL用于设置对象在cache中的最大存活时间,就是 无论对象访问或是不访问(闲置),这个对象在cache中的存活时间。
 

  
 

   overflowToDisk:当内存中对象数量达到maxElementsInMemory时,Ehcache将会对象写到磁盘中。
 

   diskSpoolBufferSizeMB:这个参数设置DiskStore(磁盘缓存)的缓存区大小。默认是30MB。每个Cache都应该有自己的一个缓冲区。
 

   maxElementsOnDisk:硬盘最大缓存个数。
 

   diskPersistent:是否缓存虚拟机重启期数据 Whether the disk store persists between restarts of the Virtual Machine. The default value is false.
 

   diskExpiryThreadIntervalSeconds:磁盘失效线程运行时间间隔,默认是120秒。
 

   memoryStoreEvictionPolicy:当达到maxElementsInMemory限制时,Ehcache将会根据指定的策略去清理内存。默认策略是LRU(最近最少使用)。你可以设置为FIFO(先进先出)或是LFU(较少使用)。
 

   clearOnFlush:内存数量最大时是否清除。

   阅读:6770 发布:2017-09-04 16:33:32

  以上就是Java Ehcache缓存的timeToIdleSeconds和timeToLiveSeconds区别(java使用cache缓存)的详细内容,想要了解更多 Java Ehcache缓存的timeToIdleSeconds和timeToLiveSeconds区别的内容,请持续关注盛行IT软件开发工作室。

郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。

留言与评论(共有 条评论)
   
验证码: