本文整理汇总了Java中net.sf.ehcache.CacheManager.create方法的典型用法代码示例。如果您正苦于以下问题:Java CacheManager.create方法的具体用法?Java CacheManager.create怎么用?Java CacheManager.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.ehcache.CacheManager
的用法示例。
在下文中一共展示了CacheManager.create方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: prep
import net.sf.ehcache.CacheManager; //导入方法依赖的package包/类
@Before
public void prep() {
this.manager = CacheManager.create();
this.manager.addCache("cascache");
this.cache = this.manager.getCache("cascache");
this.map = new EhcacheBackedMap(this.cache);
}
示例4: afterPropertiesSet
import net.sf.ehcache.CacheManager; //导入方法依赖的package包/类
public void afterPropertiesSet() throws Exception {
Configuration configuration = ConfigurationFactory.parseConfiguration();
// Override configuration to make sure cache is stored in Airsonic home dir.
File cacheDir = new File(SettingsService.getAirsonicHome(), "cache");
configuration.getDiskStoreConfiguration().setPath(cacheDir.getPath());
cacheManager = CacheManager.create(configuration);
}
示例5: 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();
}
示例6: 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();
}
示例7: start
import net.sf.ehcache.CacheManager; //导入方法依赖的package包/类
/**
* Callback to perform any necessary initialization of the underlying cache implementation
* during SessionFactory construction.
*
* @param properties current configuration settings.
*/
public void start(Properties properties) throws CacheException {
try {
manager = CacheManager.create();
}
catch (net.sf.ehcache.CacheException e) {
throw new CacheException(e);
}
}
示例8: initCacheHard
import net.sf.ehcache.CacheManager; //导入方法依赖的package包/类
/**
* Attempts to init cache to default values ignoring
* exceptions.
*/
private void initCacheHard() {
try {
CacheManager.create();
} catch (Exception e) {
log.error("Error creating cache", e);
}
}
示例9: start
import net.sf.ehcache.CacheManager; //导入方法依赖的package包/类
@Override
public void start(String resource, Map<String, String> properties) {
if (null != cacheManager) {
return;
}
try {
InputStream inputStream = Resources.getResourceAsStream(resource);
this.cacheManager = CacheManager.create(inputStream);
this.cache = cacheManager.getCache(cacheManager.getCacheNames()[0]);
} catch (Throwable e) {
throw new CacheException(e);
}
}
示例10: JbootEhcacheImpl
import net.sf.ehcache.CacheManager; //导入方法依赖的package包/类
public JbootEhcacheImpl() {
cacheManager = CacheManager.create();
}
示例11: afterPropertiesSet
import net.sf.ehcache.CacheManager; //导入方法依赖的package包/类
@Override
public void afterPropertiesSet() throws IOException, CacheException {
logger.info("Initializing EhCache CacheManager");
InputStream is = (this.configLocation != null ? this.configLocation.getInputStream() : null);
try {
Configuration configuration = (is != null ?
ConfigurationFactory.parseConfiguration(is) : ConfigurationFactory.parseConfiguration());
if (this.cacheManagerName != null) {
configuration.setName(this.cacheManagerName);
}
if (this.shared) {
// Old-school EhCache singleton sharing...
// No way to find out whether we actually created a new CacheManager
// or just received an existing singleton reference.
this.cacheManager = CacheManager.create(configuration);
}
else if (this.acceptExisting) {
// EhCache 2.5+: Reusing an existing CacheManager of the same name.
// Basically the same code as in CacheManager.getInstance(String),
// just storing whether we're dealing with an existing instance.
synchronized (CacheManager.class) {
this.cacheManager = CacheManager.getCacheManager(this.cacheManagerName);
if (this.cacheManager == null) {
this.cacheManager = new CacheManager(configuration);
}
else {
this.locallyManaged = false;
}
}
}
else {
// Throwing an exception if a CacheManager of the same name exists already...
this.cacheManager = new CacheManager(configuration);
}
}
finally {
if (is != null) {
is.close();
}
}
}
示例12: setup
import net.sf.ehcache.CacheManager; //导入方法依赖的package包/类
@Before
public void setup() {
this.cache = new Cache("test-token-store", 100, false, false, 100, 10);
this.cacheManager = CacheManager.create();
this.cacheManager.addCache(this.cache);
}
示例13: 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();
}
}
}
示例14: afterPropertiesSet
import net.sf.ehcache.CacheManager; //导入方法依赖的package包/类
@Override
public void afterPropertiesSet() throws IOException {
this.cacheManager = CacheManager.create(getInputStream());
}