• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Cache类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中net.sf.jsr107cache.Cache的典型用法代码示例。如果您正苦于以下问题:Java Cache类的具体用法?Java Cache怎么用?Java Cache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Cache类属于net.sf.jsr107cache包,在下文中一共展示了Cache类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: cache1

import net.sf.jsr107cache.Cache; //导入依赖的package包/类
@Test
public void cache1 () {

    Cache cache;

    try {
        CacheFactory cacheFactory = CacheManager.getInstance()
                .getCacheFactory();
        cache = cacheFactory.createCache(Collections.emptyMap());
    }

    catch (CacheException e) {
        // ...
        return;
    };

    cache.put("beispiel1", "Das ist ein Test");
    cache.put("beispiel2", "Das ist ein Versuch");
    cache.put("beispiel3", "Das ist ein Beispiel");

    assertEquals(cache.get("beispiel1"), "Das ist ein Test");
    assertEquals(cache.get("beispiel2"), "Das ist ein Versuch");
    assertEquals(cache.get("beispiel3"), "Das ist ein Beispiel");
}
 
开发者ID:KorAP,项目名称:Krill,代码行数:25,代码来源:TestCache.java


示例2: getSubteKeys

import net.sf.jsr107cache.Cache; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static synchronized List<Key<Line>> getSubteKeys() {
	String functionName = "getSubteKeys()";
	if(subteKeys == null || subteKeys.size() == 0) {
		Objectify ofy = ObjectifyService.begin();
		Query<Line> q = ofy.query(Line.class).filter("type", 11);
		List<Key<Line>> keys;
		try {
        	Cache cache = CacheManager.getInstance().getCacheFactory().createCache(Collections.emptyMap());
        	keys = (List<Key<Line>>)cache.get(q.toString());
        	if(keys == null) {
				keys = q.listKeys();
				cache.put(q.toString(), keys);
			}
        } catch (CacheException e) {
        	keys = q.listKeys();
        	Logger.getLogger(location).log(Level.SEVERE, functionName + ": Cache error: " + e);
        	e.printStackTrace();
        }
		subteKeys = keys;
		Logger.getLogger(location).log(Level.INFO, functionName + ": served new subteKeys. #" + subteKeys.size());
	}
	return subteKeys;
}
 
开发者ID:Hellek1,项目名称:viaja-facil,代码行数:25,代码来源:Dao.java


示例3: getTrainKeys

import net.sf.jsr107cache.Cache; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static synchronized List<Key<Line>> getTrainKeys() {
	String functionName = "getTrainKeys()";
	if(trainKeys == null || trainKeys.size() == 0) {
		Objectify ofy = ObjectifyService.begin();
		Query<Line> q = ofy.query(Line.class).filter("type", 21);
		List<Key<Line>> keys;
		try {
        	Cache cache = CacheManager.getInstance().getCacheFactory().createCache(Collections.emptyMap());
        	keys = (List<Key<Line>>)cache.get(q.toString());
        	if(keys == null) {
				keys = q.listKeys();
				cache.put(q.toString(), keys);
			}
        } catch (CacheException e) {
        	keys = q.listKeys();
        	Logger.getLogger(location).log(Level.SEVERE, functionName + ": Cache error: " + e);
        	e.printStackTrace();
        }
		trainKeys = keys;
		Logger.getLogger(location).log(Level.INFO, functionName + ": served new trainKeys. #" + trainKeys.size());
	}
	return trainKeys;
}
 
开发者ID:Hellek1,项目名称:viaja-facil,代码行数:25,代码来源:Dao.java


示例4: getPointsToDisplayForLine

import net.sf.jsr107cache.Cache; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Collection<Point> getPointsToDisplayForLine(Line l, Objectify ofy) {
	String functionName = "getPointsForLine()";
       List<Key<Point>> keys;
       Query<Point> q = ofy.query(Point.class).ancestor(l).filter("forSearchOnly", false).order("index");
       try {
       	Cache cache = CacheManager.getInstance().getCacheFactory().createCache(Collections.emptyMap());
       	keys = (List<Key<Point>>)cache.get(q.toString());
		if(keys == null) {
			keys = q.listKeys();
			cache.put(q.toString(), keys);
		}
       } catch (CacheException e) {
       	keys = q.listKeys();
       	Logger.getLogger(location).log(Level.SEVERE, functionName + ": Cache error: " + e);
       	e.printStackTrace();
       }
       Map<Key<Point>, Point> points = ofy.get(keys);
	return points.values();
}
 
开发者ID:Hellek1,项目名称:viaja-facil,代码行数:21,代码来源:Dao.java


示例5: getSearchPointsForLine

import net.sf.jsr107cache.Cache; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Collection<Point> getSearchPointsForLine(Key<Line> l, int middleIndex, int plusMinusIndex, Objectify ofy) {
       String functionName = "getSearchPointsForLine(int plusMinusIndex)";
       List<Key<Point>> keys;
       plusMinusIndex++; // query is exclusive, therefore we expand by one to return the expected number of results
       Query<Point> q = ofy.query(Point.class).ancestor(l).filter("ignore", false).filter("index <", middleIndex + plusMinusIndex).filter("index >", middleIndex - plusMinusIndex);
       try {
       	Cache cache = CacheManager.getInstance().getCacheFactory().createCache(Collections.emptyMap());
       	keys = (List<Key<Point>>)cache.get(q.toString());
       	if(keys == null) {
			keys = q.listKeys();
			cache.put(q.toString(), keys);
		}
       } catch (CacheException e) {
       	keys = q.listKeys();
       	Logger.getLogger(location).log(Level.SEVERE, functionName + ": Cache error: " + e);
       	e.printStackTrace();
       }
       Map<Key<Point>, Point> points = ofy.get(keys);
       return points.values();
}
 
开发者ID:Hellek1,项目名称:viaja-facil,代码行数:22,代码来源:Dao.java


示例6: addAndCheckSearchForIp

import net.sf.jsr107cache.Cache; //导入依赖的package包/类
public int addAndCheckSearchForIp(String ip, int mode) {
		String functionName = "addAndCheckSearchForIp()";
		Cache cache;
		Map<String, Integer> props = new HashMap<String, Integer>();
        props.put(GCacheFactory.EXPIRATION_DELTA, 600); // 10 minutes
        if(Utils.isUserInSpecialACL()) {
//        	System.err.println("No limit for user: " + Utils.getUser().getEmail() + "(" + Utils.getUser().getNickname() + ")");
        	Logger.getLogger(location).log(Level.INFO, functionName + ": No limit for user: " + Utils.getUser().getEmail() + "(" + Utils.getUser().getNickname() + ")");
        	return 1;
        }
        try {
        	String key = "requestCounter:" + mode + ":" + ip;
        	CacheFactory cacheFactory = CacheManager.getInstance().getCacheFactory();
            cache = cacheFactory.createCache(props);
            Integer counter = new Integer(1);
            Integer o = (Integer)cache.get(key);
            if(o != null) {
            	counter = counter + o;
            }
            cache.put(key, counter);
            return counter;
        } catch (CacheException e) {
        	Logger.getLogger(location).log(Level.SEVERE, functionName + ": caching error: " + e);
        	return -1;
        }
	}
 
开发者ID:Hellek1,项目名称:viaja-facil,代码行数:27,代码来源:Dao.java


示例7: getUserFavouritePositions

import net.sf.jsr107cache.Cache; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Collection<UserFavouritePosition> getUserFavouritePositions(User user, Objectify ofy) {
	String functionName = "getUserFavouritePositions()";
	Query<UserFavouritePosition> q = ofy.query(UserFavouritePosition.class).filter("user", user);
	List<Key<UserFavouritePosition>> keys;
	try {
       	Cache cache = CacheManager.getInstance().getCacheFactory().createCache(Collections.emptyMap());
       	keys = (List<Key<UserFavouritePosition>>)cache.get(q.toString());
       	if(keys == null) {
			keys = q.listKeys();
			cache.put(q.toString(), keys);
		}
       } catch (CacheException e) {
       	Logger.getLogger(location).log(Level.SEVERE, functionName + ": caching error: " + e);
       	keys = q.listKeys();
       }
       return ofy.get(keys).values();
}
 
开发者ID:Hellek1,项目名称:viaja-facil,代码行数:19,代码来源:Dao.java


示例8: doGet

import net.sf.jsr107cache.Cache; //导入依赖的package包/类
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

		CacheFactory cacheFactory;
		try {
			cacheFactory = CacheManager.getInstance().getCacheFactory();
			Cache cache;
			cache = cacheFactory.createCache(Collections.emptyMap());
			
			cache.clear();
			
			DataService.getInstance().saveConfig();
		} catch (CacheException e) {
			log.log(Level.SEVERE, "Error instantiating Cache");
		}
		log.log(Level.WARNING, "Cleared the Cache");
	}
 
开发者ID:Rise-Vision,项目名称:rva,代码行数:17,代码来源:MemCacheClearServlet.java


示例9: resetTrainNodes

import net.sf.jsr107cache.Cache; //导入依赖的package包/类
public String resetTrainNodes() throws IllegalArgumentException {
	try {
		Cache cache = CacheManager.getInstance().getCacheFactory().createCache(Collections.emptyMap());
		cache.clear();
	} catch (CacheException e) {
		e.printStackTrace();
	}
	Dao.resetTrainNodes();
	Dao.getTrainNodes();
	Dao.getTrainNodeKeyMap();
	Dao.getSubteKeys();
	Dao.getTrainKeys();
	return "done";
}
 
开发者ID:Hellek1,项目名称:viaja-facil,代码行数:15,代码来源:LineListServiceImpl.java


示例10: getTrainNodes

import net.sf.jsr107cache.Cache; //导入依赖的package包/类
@SuppressWarnings("unchecked")
	public static synchronized HashMap<String,Set<TrainNode>> getTrainNodes() {
		String functionName = "getTrainNodes()";
		if(trainNodes == null || trainNodes.size() == 0) {
			trainNodes = new HashMap<String,Set<TrainNode>>();
			Objectify ofy = ObjectifyService.begin();
			Query<TrainNode> q = ofy.query(TrainNode.class);
			List<Key<TrainNode>> keys;
			try {
	        	Cache cache = CacheManager.getInstance().getCacheFactory().createCache(Collections.emptyMap());
	        	keys = (List<Key<TrainNode>>)cache.get(q.toString());
	        	if(keys == null) {
					keys = q.listKeys();
					cache.put(q.toString(), keys);
				}
	        } catch (CacheException e) {
	        	keys = q.listKeys();
	        	Logger.getLogger(location).log(Level.SEVERE, functionName + ": Cache error: " + e);
	        	e.printStackTrace();
	        }
	        Map<Key<TrainNode>, TrainNode> res = ofy.get(keys);
			Collection<TrainNode> tns = res.values();
			Logger.getLogger(location).log(Level.INFO, functionName + ": Got " + res.size() + " TrainNodes. keys.size(): " + keys.size());			
//			String m = "";
			for(TrainNode tn : tns) {
				if(!trainNodes.containsKey(tn.getGeoCell())) {
					trainNodes.put(tn.getGeoCell(), new HashSet<TrainNode>());
				}
				trainNodes.get(tn.getGeoCell()).add(tn);
/*				if(tn.getLineKey().equals(new Key<Line>(Line.class, 155))) {
//				if(tn.getLineType() == 11) {
					System.err.print("\"" + tn.getGeoCell() + "\", ");
				}*/
			}
//			Utils.eMailGeneric(m, "DaoTemp");
		}
		return trainNodes;
	}
 
开发者ID:Hellek1,项目名称:viaja-facil,代码行数:39,代码来源:Dao.java


示例11: removeFromCache

import net.sf.jsr107cache.Cache; //导入依赖的package包/类
private void removeFromCache(Object key) {
	try {
		Cache cache = CacheManager.getInstance().getCacheFactory().createCache(Collections.emptyMap());
       	cache.remove(key);
       } catch (CacheException e) {
       	Logger.getLogger(location).log(Level.SEVERE, "removeFromCache(): Cache error: " + e);
       	e.printStackTrace();
       }
}
 
开发者ID:Hellek1,项目名称:viaja-facil,代码行数:10,代码来源:Dao.java


示例12: getDistributedMap

import net.sf.jsr107cache.Cache; //导入依赖的package包/类
public Map getDistributedMap(String name) {
	Cache sharedCache = null;
	try {
		sharedCache = net.sf.jsr107cache.CacheManager.getInstance().getCache(name);
		if (sharedCache == null) {
			sharedCache = net.sf.jsr107cache.CacheManager.getInstance().getCacheFactory().createCache(Collections.emptyMap());
			net.sf.jsr107cache.CacheManager.getInstance().registerCache(name, sharedCache);
        }
	} catch (Exception e) {
		e.printStackTrace();
		throw new IllegalStateException(e.getMessage());
	}
	return sharedCache;
}
 
开发者ID:qafedev,项目名称:qafe-platform,代码行数:15,代码来源:CacheManager.java


示例13: provideCache

import net.sf.jsr107cache.Cache; //导入依赖的package包/类
@Provides
Cache provideCache() {
  try {
    CacheFactory cacheFactory = CacheManager.getInstance().getCacheFactory();
    return cacheFactory.createCache(Collections.emptyMap());
  } catch (CacheException e) {
    // ...
  }
  return null;
}
 
开发者ID:larrytin,项目名称:realtime-server-appengine,代码行数:11,代码来源:AppEngineModule.java


示例14: createCache

import net.sf.jsr107cache.Cache; //导入依赖的package包/类
/**
 * Create a {@link Cache} from the default {@code net.sf.jsr107cache}
 * implementation with no custom properties.
 */
private Cache createCache() throws ServletException {
  Map<String, Object> props = Collections.emptyMap();
  try {
    return CacheManager.getInstance().getCacheFactory().createCache(props);
  } catch (CacheException ex) {
    throw new ServletException("Could not initialize cache:", ex);
  }
}
 
开发者ID:dougkoellmer,项目名称:swarm,代码行数:13,代码来源:FractalTileServlet.java


示例15: getCache

import net.sf.jsr107cache.Cache; //导入依赖的package包/类
protected Cache getCache() {
	return cache;
}
 
开发者ID:WELTEN,项目名称:dojo-ibl,代码行数:4,代码来源:GenericCache.java


示例16: getCache

import net.sf.jsr107cache.Cache; //导入依赖的package包/类
@Override
protected Cache getCache() {
	return cache;
}
 
开发者ID:WELTEN,项目名称:dojo-ibl,代码行数:5,代码来源:ProgressRecordCache.java


示例17: getCache

import net.sf.jsr107cache.Cache; //导入依赖的package包/类
public Cache getCache() {
	return cache;
}
 
开发者ID:WELTEN,项目名称:dojo-ibl,代码行数:4,代码来源:FusionCache.java


示例18: setCache

import net.sf.jsr107cache.Cache; //导入依赖的package包/类
/**
 * Set the cache to use for this repository. If a cache is not set, caching is disabled for this implementation.
 *
 * @param cache the cache to use
 */
public void setCache(Cache cache) {
    this.cache = cache;
}
 
开发者ID:slowlizard,项目名称:cqrs4j,代码行数:9,代码来源:CachingEventSourcingRepository.java


示例19: getCache

import net.sf.jsr107cache.Cache; //导入依赖的package包/类
protected abstract Cache getCache(); 
开发者ID:WELTEN,项目名称:dojo-ibl,代码行数:2,代码来源:RunCache.java



注:本文中的net.sf.jsr107cache.Cache类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java HTMLFileExport类代码示例发布时间:2022-05-22
下一篇:
Java FindCallback类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap