java 堆外缓存框架-java缓存框架 学哪个先
发布时间:2023-04-04 22:04 浏览次数:次 作者:佚名
记得之前分享过的一款Java分布式缓存系统Ehcache,可以有效地减轻数据库的读写负担,提高Web系统的吞吐率。这次介绍的Cacheonix同样也是一个基于Java的分布式集群缓存系统java 堆外缓存框架java 堆外缓存框架,它同样可以帮助你实现分布式缓存的部署。
Cacheonix的特点 Cacheonix的架构图
Cacheonix分布式缓存XML配置
Cacheonix缓存的存取
从配置中获取Cacheonix实例
/** * Tester for CacheManager. */ public final class CacheonixTest extends TestCase { private Cacheonix cacheonix; /** * Tests getting an instance of CacheManager using a default Cacheonix configuration. */ public void testGetInstance() { assertNotNull("Cacheonix created in setUp() method should not be null", cacheonix); } /** * Sets up the fixture. This method is called before a test is executed. * * Cacheonix receives the default configuration from acacheonix-config.xml
found in a class path or * using a file that name is defined by system parametercacheonix.config.xml
. */ protected void setUp() throws Exception { super.setUp(); // Get Cacheonix using a default Cacheonix configuration. The configuration // is stored in the conf/cacheonix-config.xml cacheonix = Cacheonix.getInstance(); } /** * Tears down the fixture. This method is called after a test is executed. */ protected void tearDown() throws Exception { // Cache manager has be be shutdown upon application exit. // Note that call to shutdown() here uses unregisterSingleton // set to true. This is necessary to support clean restart on setUp() cacheonix.shutdown(ShutdownMode.GRACEFUL_SHUTDOWN, true); cacheonix = null; super.tearDown(); } }
读取缓存
Cacheonix cacheonix = Cacheonix.getInstance(); Cachecache = cacheonix.getCache("my.cache"); String cachedValue = cache.get("my.key");
设置缓存
Cacheonix cacheonix = Cacheonix.getInstance(); Cachecache = cacheonix.getCache("my.cache"); String replacedValue = cache.put("my.key", "my.value");
删除缓存
Cacheonix cacheonix = Cacheonix.getInstance(); Cachecache = cacheonix.getCache("my.cache"); String removedValue = cache.remove("my.key");
Cacheonix作为一款开源的分布式缓存框架,可以满足中型企业规模的系统架构,对提升系统性能有非常棒的作用。
本文链接: