本文整理匯總了Java中net.sf.ehcache.CacheManager.getCache方法的典型用法代碼示例。如果您正苦於以下問題:Java CacheManager.getCache方法的具體用法?Java CacheManager.getCache怎麽用?Java CacheManager.getCache使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.sf.ehcache.CacheManager
的用法示例。
在下文中一共展示了CacheManager.getCache方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createCachePool
import net.sf.ehcache.CacheManager; //導入方法依賴的package包/類
@Override
public CachePool createCachePool(String poolName, int cacheSize,
int expiredSeconds) {
CacheManager cacheManager = CacheManager.create();
Cache enCache = cacheManager.getCache(poolName);
if (enCache == null) {
CacheConfiguration cacheConf = cacheManager.getConfiguration()
.getDefaultCacheConfiguration().clone();
cacheConf.setName(poolName);
if (cacheConf.getMaxEntriesLocalHeap() != 0) {
cacheConf.setMaxEntriesLocalHeap(cacheSize);
} else {
cacheConf.setMaxBytesLocalHeap(String.valueOf(cacheSize));
}
cacheConf.setTimeToIdleSeconds(expiredSeconds);
Cache cache = new Cache(cacheConf);
cacheManager.addCache(cache);
return new EnchachePool(poolName,cache,cacheSize);
} else {
return new EnchachePool(poolName,enCache,cacheSize);
}
}
示例2: createCachePool
import net.sf.ehcache.CacheManager; //導入方法依賴的package包/類
@Override
public CachePool createCachePool(String poolName, int cacheSize,
int expiredSeconds) {
CacheManager cacheManager = CacheManager.create();
Cache enCache = cacheManager.getCache(poolName);
if (enCache == null) {
CacheConfiguration cacheConf = cacheManager.getConfiguration().getDefaultCacheConfiguration().clone();
cacheConf.setName(poolName);
if (cacheConf.getMaxEntriesLocalHeap() != 0) {
cacheConf.setMaxEntriesLocalHeap(cacheSize);
} else {
cacheConf.setMaxBytesLocalHeap(String.valueOf(cacheSize));
}
cacheConf.setTimeToIdleSeconds(expiredSeconds);
Cache cache = new Cache(cacheConf);
cacheManager.addCache(cache);
return new EnchachePool(poolName, cache, cacheSize);
} else {
return new EnchachePool(poolName, enCache, cacheSize);
}
}
示例3: RealCache
import net.sf.ehcache.CacheManager; //導入方法依賴的package包/類
public RealCache() {
super();
CacheManager manager = null;
synchronized (RealCache.class) {
manager = CacheManager.getInstance();
if (!manager.cacheExists("AFPDataGrabberCache")) {
Cache cache = new Cache(new CacheConfiguration("AFPDataGrabberCache", 50000).memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LFU)
.eternal(true).timeToLiveSeconds(0).timeToIdleSeconds(0).persistence(new PersistenceConfiguration().strategy(Strategy.NONE)));
manager.addCache(cache);
}
}
ehcache = manager.getCache("AFPDataGrabberCache");
}
示例4: testEhcache
import net.sf.ehcache.CacheManager; //導入方法依賴的package包/類
@Test
public void testEhcache() {
// Creating a CacheManager based on a specified configuration file.
CacheManager manager = CacheManager.newInstance("src/main/resources/ehcache.xml");
// obtains a Cache called sampleCache1, which has been preconfigured in the configuration file
Cache cache = manager.getCache("sampleCache1");
// puts an element into a cache
Element element = new Element("key1", "哈哈");
cache.put(element);
//The following gets a NonSerializable value from an element with a key of key1.
Object value = element.getObjectValue();
System.out.println(value.toString());
manager.shutdown();
}
示例5: getCache
import net.sf.ehcache.CacheManager; //導入方法依賴的package包/類
/**
* 獲取緩存
* @param cacheName
* @return
*/
private static Cache getCache(String cacheName) {
CacheManager cacheManager = CacheManager.getInstance();
if (null == cacheManager) {
return null;
}
Cache cache = cacheManager.getCache(cacheName);
if (null == cache) {
return null;
}
return cache;
}
示例6: cacheExposesMetrics
import net.sf.ehcache.CacheManager; //導入方法依賴的package包/類
@Test
void cacheExposesMetrics() {
CacheManager cacheManager = CacheManager.newInstance();
cacheManager.addCache("a");
Cache c = cacheManager.getCache("a");
MeterRegistry registry = new SimpleMeterRegistry();
EhCache2Metrics.monitor(registry, c, "ehcache", emptyList());
c.put(new Element("k", "v", 1));
registry.mustFind("ehcache.size").tags("name", "a").gauge();
}
示例7: onSetUpInTransaction
import net.sf.ehcache.CacheManager; //導入方法依賴的package包/類
protected void onSetUpInTransaction() {
// make a cache
CacheManager cacheManager = CacheManager.create();
if (! cacheManager.cacheExists("ehcache.sakai.kaltura.entries")) {
cacheManager.addCache("ehcache.sakai.kaltura.entries");
}
Ehcache entriesCache = cacheManager.getCache("ehcache.sakai.kaltura.entries");
// create and setup the object to be tested
external = new ExternalLogicStub();
service = new KalturaAPIService();
service.setExternal(external);
service.setEntriesCache(entriesCache);
service.setOffline(true); // for testing we do not try to fetch real data
// run the init
external.currentUserId = FakeDataPreload.ADMIN_USER_ID; // DEFAULT ADMIN
// UNICON settings for testing
external.config.put("kaltura.partnerid", 166762);
external.config.put("kaltura.adminsecret", "26d08a0ba54c911492bbc7599028295f");
external.config.put("kaltura.secret", "6e4755b613a38b19e4cfb5d7405ed170");
service.testWSInit(); // SPECIAL INIT
service.getKalturaClient();
}
示例8: setUp
import net.sf.ehcache.CacheManager; //導入方法依賴的package包/類
@Override
protected void setUp() throws Exception {
// THIS IS EXECUTED BEFORE EACH TEST
// make the caches
CacheManager cacheManager = CacheManager.create();
if (! cacheManager.cacheExists("ehcache.sakai.kaltura.entries")) {
cacheManager.addCache("ehcache.sakai.kaltura.entries");
}
Ehcache entriesCache = cacheManager.getCache("ehcache.sakai.kaltura.entries");
if (! cacheManager.cacheExists("ehcache.sakai.kaltura.cats")) {
cacheManager.addCache("ehcache.sakai.kaltura.cats");
}
Ehcache categoriesCache = cacheManager.getCache("ehcache.sakai.kaltura.cats");
// create and setup the object to be tested
external = new ExternalLogicStub();
kalturaAPIService = new KalturaAPIServiceStub(external, entriesCache, categoriesCache);
kalturaAPIService.setKalturaClippingEnabled(true); // for testing
service = new MediaService();
service.setExternal(external);
service.setKalturaAPIService(kalturaAPIService);
service.setEntriesCache(entriesCache);
service.setForceMediaNameOrdering(false);
// run the init
service.init();
}
示例9: getRetentionCache
import net.sf.ehcache.CacheManager; //導入方法依賴的package包/類
/**
* Returns reference to retention cache
*/
private RetentionCache getRetentionCache() throws CacheException {
final CacheManager manager = CacheManager.getInstance();
final Cache cache = manager.getCache("retention_cache");
if (cache == null) {
return DUMMY_STATELESS_RETENTION_CACHE;
} else {
return new DelegatingRetentionCache(cache);
}
}
示例10: main
import net.sf.ehcache.CacheManager; //導入方法依賴的package包/類
/**
* Run an ehcache based client, against the Terracotta Server
*
*/
public static void main(String[] args) throws IOException {
String terracottaServerUrl = System.getenv("TERRACOTTA_SERVER_URL");
if(terracottaServerUrl == null || terracottaServerUrl.trim().equals("")) {
System.out.println("The environment variable TERRACOTTA_SERVER_URL was not set; using terracotta:9510 as the cluster url.");
terracottaServerUrl = "terracotta:9510";
}
System.out.println("**** Programmatically configure an instance, configured to connect to : " + terracottaServerUrl + " ****");
Configuration managerConfiguration = new Configuration()
.name("myCacheManager")
.terracotta(new TerracottaClientConfiguration().url(terracottaServerUrl))
.cache(new CacheConfiguration()
.name("myCache")
.maxEntriesLocalHeap(50)
.copyOnRead(true)
.eternal(true)
.terracotta(new TerracottaConfiguration())
);
CacheManager manager = CacheManager.create(managerConfiguration);
try {
Cache myCache = manager.getCache("myCache");
//myCache is now ready.
Random random = new Random();
if (myCache.getSize() > 0) {
System.out.println("**** We found some data in the cache ! I guess some other client inserted data in BigMemory ! **** ");
}
System.out.println("**** Starting inserting / getting elements **** ");
while (!Thread.currentThread().isInterrupted() && manager.getStatus() == Status.STATUS_ALIVE) {
// indexes spread between 0 and 999
int index = random.nextInt(1000);
if (random.nextInt(10) < 3 && myCache.getSize() < 1000) {
// put
String value = new BigInteger(1024 * 128 * (1 + random.nextInt(10)), random).toString(16);
System.out.println("Inserting at key " + index + " String of size : " + value.length() + " bytes");
myCache.put(new Element(index, value)); // construct a big string of 256k data
} else {
// get
Element element = myCache.get(index);
System.out.println("Getting key " + index + (element == null ? ", that was a miss" : ", THAT WAS A HIT !"));
}
Thread.sleep(100);
}
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
if (manager != null) {
manager.shutdown();
}
}
}
示例11: createCache
import net.sf.ehcache.CacheManager; //導入方法依賴的package包/類
public static Cache createCache(final CacheManager cacheManager, final Cache cache) throws CacheException {
cacheManager.addCache(cache);
return cacheManager.getCache(cache.getName());
}
示例12: makeCacheStatsPanel
import net.sf.ehcache.CacheManager; //導入方法依賴的package包/類
/**
* Creates cache stats panel.
*/
private Panel makeCacheStatsPanel() {
final MessagePanel result = new MessagePanel("Cache statistis");
try {
final GridIterator gi = new GridIterator(result.getUserPanel(), 5);
gi.add(new BoldCommonLabel("Name"))
.add(new BoldCommonLabel("Hit count"))
.add(new BoldCommonLabel("Miss count expired"))
.add(new BoldCommonLabel("Miss count not found"))
.add(new BoldCommonLabel("Miss percent"))
;
final CacheManager cacheMan = CacheManager.getInstance();
final String[] cacheNames = cacheMan.getCacheNames();
Arrays.sort(cacheNames);
int totalHitCount = 0;
int totalMissCount = 0;
for (int i = 0; i < cacheNames.length; i++) {
// get cache
final String cacheName = cacheNames[i];
final Cache cache = cacheMan.getCache(cacheName);
final int hitCount = cache.getHitCount();
final int missCountExpired = cache.getMissCountExpired();
final int missCountNotFound = cache.getMissCountNotFound();
final int missCount = missCountExpired + missCountNotFound;
final int accessCount = missCount + hitCount;
final int missPercent = accessCount == 0 ? 0 : (missCount * 100) / accessCount;
totalHitCount += hitCount;
totalMissCount += missCount;
// add attrs
gi.add(new AboutLabel(cacheName));
gi.add(new AboutLabel(Integer.toString(hitCount)));
gi.add(new AboutLabel(Integer.toString(missCountExpired)));
gi.add(new AboutLabel(Integer.toString(missCountNotFound)));
final CommonLabel lbMissPercent = new AboutLabel(Integer.toString(missPercent));
lbMissPercent.setAlignX(Layout.RIGHT);
gi.add(lbMissPercent);
}
// add total
final int totalAccessCount = totalHitCount + totalMissCount;
final int totalMissPercent = totalAccessCount == 0 ? 0 : (totalMissCount * 100) / totalAccessCount;
gi.add(new CommonLabel("--- Total -- "));
gi.add(new CommonLabel(""));
gi.add(new CommonLabel(""));
gi.add(new CommonLabel(""));
gi.add(new CommonLabel(Integer.toString(totalMissPercent)));
} catch (CacheException e) {
result.showErrorMessage("Error getting cache stats: " + e.toString());
}
return result;
}