Ehcache 1.5.0 User Guide - Code Samples 代码实例2
2009-07-13 11:04
399 查看
Ehcache 1.5.0 User Guide - Code Samples 代码实例2
Ehcache 1.5.0 用户指南)
E_mail:jianglike18@163.con
Blog: http://blog.csdn.net/jianglike18
qq:29396597
8.1.3 Adding and Removing Caches Programmatically(编程的添加和移除缓存)
You are not just stuck with the caches that were placed in the configuration. You can create and remove them programmatically.Add a cache using defaults, then use it. The following example creates a cache called testCache, which will be configured using defaultCache from the configuration.(你不要被束缚了认为缓存只能在配置文件设置。你还可以编程的增加或移除。使用默认的配置添加一个缓存,然后使用它。下面的例子创建了名为testCache的缓存,该缓存使用配置文件的默认缓存设置。) CacheManager singletonManager = CacheManager.create();singletonManager.addCache("testCache");Cache test = singletonManager.getCache("testCache"); Create a Cache and add it to the CacheManager, then use it. Note that Caches are not usable until they have been added to a CacheManager. (创建一个缓存并添加至CacheManager对象,然后使用它。注意缓存添加至CacheManager对象后才可以使用。) CacheManager singletonManager = CacheManager.create();Cache memoryOnlyCache = new Cache("testCache", 5000, false, false, 5, 2);manager.addCache(memoryOnlyCache);Cache test = singletonManager.getCache("testCache"); See Cache#Cache(...) for the full parameters for a new Cache: Remove cache called sampleCache1(移除缓存sampleCache1) CacheManager singletonManager = CacheManager.create();singletonManager.removeCache("sampleCache1");8.1.4 Shutdown the CacheManager(关闭缓存)
Ehcache should be shutdown after use. It does have a shutdown hook, but it is best practice to shut it down in your code.(Ehcache 使用后应该关闭。它有一个关闭的钩子,但是最好的办法是在你的代码进行关闭。) Shutdown the singleton CacheManager(关闭单实例的CacheManager对象。) CacheManager.getInstance().shutdown(); Shutdown a CacheManager instance, assuming you have a reference to the CacheManager called manager(关闭一个CacheManager实例,假定你有一个CacheManager对象的应用manager)manager.shutdown(); See the CacheManagerTest for more examples.(查看CacheManagerTest获取更多的例子。)
相关文章推荐
- Ehcache 1.5.0 User Guide - Code Samples 代码实例 (1)
- Ehcache 1.5.0 User Guide - Code Samples 代码实例 3
- Ehcache 1.5.0 User Guide - Java Requirements and Dependencies JAVA要求和依赖
- Ehcache 1.5.0 User Guide - preface(序言)
- Ehcache 1.5.0 User Guide - Dependencies(依赖)
- Ehcache 1.5.0 User Guide - Cache Eviction Algorithms (缓存移出算法)
- Ehcache 1.5.0 User Guide - Logging 日志(10)
- Ehcache 1.5.0 User Guide - Cache Configuration 缓存配置(3)
- Ehcache 1.5.0 User Guide - Introduction (介绍)(2)
- Ehcache 1.5.0 User Guide - Cache Configuration 缓存配置(1)
- Ehcache 1.5.0 User Guide - Remote Network debugging and monitoring for Distributed Caches(远程调式和跟踪分布式缓存)(11)
- Ehcache 1.5.0 User Guide - Introduction (介绍)(1)
- Ehcache 1.5.0 User Guide - Getting Started(开始)
- Ehcache 1.5.0 User Guide - Cache Concepts (缓存概念)
- Ehcache 1.5.0 User Guide - Cache Configuration 缓存配置(2)
- Java缓存Ehcache-核心类和方法介绍及代码实例
- ehcache实例代码
- 详解SpringBoot缓存的实例代码(EhCache 2.x 篇)
- 基于jQuery实现美观且实用的倒计时实例代码
- C#中把Datatable转换为Json的5个代码实例