| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
9年前发布

Java分布式集群缓存框架:Cacheonix

记得之前分享过的一款Java分布式缓存系统Ehcache,可以有效地减轻数据库的读写负担,提高Web系统的吞吐率。这次介绍的Cacheonix同样也是一个基于Java的分布式集群缓存系统,它同样可以帮助你实现分布式缓存的部署。

Java分布式集群缓存框架:Cacheonix

Cacheonix的特点

  • 可靠的分布式 Java 缓存
  • 通过复制实现高可用性
  • 支持泛型的缓存 API
  • 可与 ORM 框架集成
  • 使用数据分区实现负载均衡
  • 支持非多播网络
  • 高性能计算
  • 快速的本地 Java 缓存
  • 分布式锁机制

Cacheonix的架构图

Java分布式集群缓存框架:Cacheonix

Cacheonix分布式缓存XML配置

<?xml version ="1.0"?>  <cacheonix xmlns="http://www.cacheonix.com/schema/configuration"             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"             xsi:schemaLocation="http://www.cacheonix.com/schema/configuration http://www.cacheonix.com/schema/cacheonix-config-2.0.xsd">       <server>          <listener>           <tcp port="8879" buffer="128k"/>        </listener>          <broadcast>           <multicast multicastAddress="225.0.1.2" multicastPort="9998" multicastTTL="0"/>        </broadcast>          <partitionedCache name="customer.cache">           <store>              <lru maxElements="10000" maxBytes="10mb"/>              <expiration idleTime="120s"/>           </store>        </partitionedCache>          <partitionedCache name="invoice.cache">           <store>              <lru maxElements="10000" maxBytes="10mb"/>              <expiration idleTime="120s"/>           </store>        </partitionedCache>          <partitionedCache name="search.results.cache">           <store>              <lru maxBytes="5mb"/>           </store>        </partitionedCache>     </server>  </cacheonix>

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.      * <p/>      * Cacheonix receives the default configuration from a <code>cacheonix-config.xml</code> found in a class path or      * using a file that name is defined by system parameter <code>cacheonix.config.xml<code>.      */     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();  Cache<String, String> cache = cacheonix.getCache("my.cache");  String cachedValue = cache.get("my.key");

设置缓存

Cacheonix cacheonix = Cacheonix.getInstance();  Cache<String, String> cache = cacheonix.getCache("my.cache");  String replacedValue = cache.put("my.key", "my.value");

删除缓存

Cacheonix cacheonix = Cacheonix.getInstance();  Cache<String, String> cache = cacheonix.getCache("my.cache");  String removedValue = cache.remove("my.key");

Cacheonix作为一款开源的分布式缓存框架,可以满足中型企业规模的系统架构,对提升系统性能有非常棒的作用。

本文链接:http://www.codeceo.com/article/java-cacheonix.html

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1414903281012.html
Cacheonix 缓存组件