SHOP.COM Cache System 介绍
这是SHOP.COM 网站所使用的对象缓存系统,主要特性包括如下几个方面:
- 支持进程内和CS 模式的缓存结构
- 可以进行水平扩展
- 缓存对象可被存到磁盘中
- 支持关联主键
- 非事务
- 支持任意长度的主键和键值
- 根据 TTL 进行自动垃圾回收
- 可以运行于容器中或者是独立平台运行
示例代码:
List<SCClientManager> clientSet = new ArrayList<SCClientManager>(); SCClientFactory clientFactory = ShopComCacheFactory.getClientFactory(); SCClientContext context = clientFactory.newContext(); context.address(new InetSocketAddress(/*address 1*/, /*port number 1*/)); SCClientManager manager = clientFactory.newClientManager(context); clientSet.add(manager); // add additional managers for each cache server myCache = new SCCache(new SCMultiManager(clientSet)); // see if your object is in the cache MyObject obj = (MyObject)myCache.get(new SCDataBlock(myKey)); // if it's not, allocate it and add it to the cache if ( obj == null ) { obj = new MyObject(); myCache.put(new SCDataBlock(myKey, obj)); }