java缓存集群_Cacheonix:Java分布式集群缓存框架

记得之前分享过的一款Java分布式缓存系统

0818b9ca8b590ca3270a3433284dd417.png

Cacheonix的特点

可靠的分布式 Java 缓存

通过复制实现高可用性

支持泛型的缓存 API

可与 ORM 框架集成

使用数据分区实现

支持非多播网络

高性能计算

快速的本地 Java 缓存

分布式锁机制

Cacheonix的架构图

0818b9ca8b590ca3270a3433284dd417.png

Cacheonix分布式缓存XML配置

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">

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 a cacheonix-config.xml found in a class path or

* using a file that name is defined by system parameter cacheonix.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();

Cache cache = cacheonix.getCache("my.cache");

String cachedValue = cache.get("my.key");

设置缓存

Cacheonix cacheonix = Cacheonix.getInstance();

Cache cache = cacheonix.getCache("my.cache");

String replacedValue = cache.put("my.key", "my.value");

删除缓存

Cacheonix cacheonix = Cacheonix.getInstance();

Cache cache = cacheonix.getCache("my.cache");

String removedValue = cache.remove("my.key");

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值