3

アプリケーションでいくつかのキャッシングメカニズムを使用することを計画しており、他の多くのキャッシングソリューションとの比較研究を行った後、Javaキャッシングシステム(JCS)を選択しました。外部構成(cache.ccf)を使用してキャッシュ領域とそのプロパティ(maxlife、ideltimeなど)を定義すると、すべて問題ありません。

ただし、要件は動的キャッシュ領域を持つように変更されています。つまり、実行時にキャッシュ領域とそのプロパティを定義する必要があります。この操作に関する詳細やサンプルを見つけることができません。実行時にキャッシュ領域を正常に作成しました(以下のメソッドシグネチャを使用)。

ICompositeCacheAttributes  cattr=..
IElementAttributes attr = new ElementAttributes();
attr.setIsEternal(false);
attr.setMaxLifeSeconds( maxLife );    
defineRegion(name,  cattr,attr);

ただし、問題は、IElmentAttributesがキャッシュに設定されないことです。私はJCSのソースについて調査しましたが、attr設定されていないことがわかりました。未使用の引数です!! 少し奇妙

さらにグーグルした後、属性を手動で設定するための以下のオプションを見つけましたが、それでも機能しませんでした

 IElementAttributes attr = new ElementAttributes();
 attr.setIsEternal(false);
 attr.setMaxLifeSeconds( maxLife );
 jcs.setDefaultElementAttributes(attr);

作成したリージョンにmaxLifeSecondsを設定するだけです。

4

2 に答える 2

2

私は自分の問題を解決する方法を見つけました。データをキャッシュに入れるときに属性を設定する必要があります。興味のある人のために実装を見てください、

JCS jcs = JCS.getInstance("REGION");
IElementAttributes attr = new ElementAttributes();
attr.setIsEternal(false);
attr.setMaxLifeSeconds( maxLife );
jcs.put("Key",data, attr);
于 2012-10-19T17:43:31.207 に答える
2

ここにサンプルコード

Properties props = new Properties();
//
// Default cache configs
//
props.put("jcs.default", "");
props.put("jcs.default.cacheattributes","org.apache.jcs.engine.CompositeCacheAttributes");
props.put("jcs.default.cacheattributes.MaxObjects","1000");
props.put("jcs.default.cacheattributes.MemoryCacheName", "org.apache.jcs.engine.memory.lru.LRUMemoryCache");
props.put("jcs.default.cacheattributes.UseMemoryShrinker", "true");
props.put("jcs.default.cacheattributes.MaxMemoryIdleTimeSeconds", "3600");
props.put("jcs.default.cacheattributes.ShrinkerIntervalSeconds", "60");
props.put("jcs.default.cacheattributes.MaxSpoolPerRun", "500");

//
// Region cache
//
props.put("jcs.region.myregionCache", "");
props.put("jcs.region.myregionCache.cacheattributes", "org.apache.jcs.engine.CompositeCacheAttributes");
props.put("jcs.region.myregionCache.cacheattributes.MaxObjects", "1000");
props.put("jcs.region.myregionCache.cacheattributes.MemoryCacheName", "org.apache.jcs.engine.memory.lru.LRUMemoryCache");
props.put("jcs.region.myregionCache.cacheattributes.UseMemoryShrinker", "true");
props.put("jcs.region.myregionCache.cacheattributes.MaxMemoryIdleTimeSeconds", "3600");
props.put("jcs.region.myregionCache.cacheattributes.ShrinkerIntervalSeconds", "60");
props.put("jcs.region.myregionCache.cacheattributes.MaxSpoolPerRun", "500");
props.put("jcs.region.myregionCache.cacheattributes.DiskUsagePatternName", "UPDATE");
props.put("jcs.region.myregionCache.elementattributes", "org.apache.jcs.engine.ElementAttributes");
props.put("jcs.region.myregionCache.elementattributes.IsEternal", "false");

...


// Configure
CompositeCacheManager ccm = CompositeCacheManager.getUnconfiguredInstance();
ccm.configure(props);

// Access region
CompositeCache myregionCache =  ccm.getCache("myregionCache");

...
于 2015-01-11T19:29:58.270 に答える