本文整理汇总了Java中net.sf.ehcache.Element类的典型用法代码示例。如果您正苦于以下问题:Java Element类的具体用法?Java Element怎么用?Java Element使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Element类属于net.sf.ehcache包,在下文中一共展示了Element类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cacheMonitor
import net.sf.ehcache.Element; //导入依赖的package包/类
@Around("execution(* org.packt.aop.transaction.dao.impl.EmployeeDaoImpl.getEmployees(..))")
public Object cacheMonitor(ProceedingJoinPoint joinPoint) throws Throwable {
logger.info("executing " + joinPoint.getSignature().getName());
Cache cache = cacheManager.getCache("employeesCache");
logger.info("cache detected is " + cache.getName());
logger.info("begin caching.....");
String key = joinPoint.getSignature().getName();
logger.info(key);
if(cache.get(key) == null){
logger.info("caching new Object.....");
Object result = joinPoint.proceed();
cache.put(new Element(key, result));
return result;
}else{
logger.info("getting cached Object.....");
return cache.get(key).getObjectValue();
}
}
示例2: sendRepassword
import net.sf.ehcache.Element; //导入依赖的package包/类
/** 비밀번호를 재발급을 위한 메서드
* @param email
* @return 성공여부
*/
public boolean sendRepassword(String email){
Cache rePasswordCache = cacheManager.getCache("repassword");
Object object = rePasswordCache.get(email);
if(object != null || weaverDao.get(email) == null) //등록된 이메일이 없을 경우.
return false;
String password = KeyGenerators.string().generateKey().substring(0, 7);
String key = passwordEncoder.encodePassword(password, null);
RePassword rePassword = new RePassword(key, password);
mailUtil.sendMail(email,"[forweaver] 비밀번호 재발급",
"링크 - http://forweaver.com/repassword/"+email+"/"+key+"\n"+
"변경된 비밀번호 - "+password+"\n"+
"\n링크에 5분이내에 접속하시고 나서 변경된 비밀번호로 로그인해주세요!");
Element newElement = new Element(email, rePassword);
rePasswordCache.put(newElement);
return true;
}
示例3: getTicket
import net.sf.ehcache.Element; //导入依赖的package包/类
@Override
public Ticket getTicket(final String ticketIdToGet) {
final String ticketId = encodeTicketId(ticketIdToGet);
if (ticketId == null) {
return null;
}
Element element = this.serviceTicketsCache.get(ticketId);
if (element == null) {
element = this.ticketGrantingTicketsCache.get(ticketId);
}
if (element == null) {
logger.debug("No ticket by id [{}] is found in the registry", ticketId);
return null;
}
final Ticket proxiedTicket = decodeTicket((Ticket) element.getObjectValue());
final Ticket ticket = getProxiedTicketInstance(proxiedTicket);
return ticket;
}
示例4: push
import net.sf.ehcache.Element; //导入依赖的package包/类
/** 글 추천하면 캐시에 저장하고 24시간 제한을 둠.
* @param post
* @param weaver
* @return
*/
public boolean push(Post post, Weaver weaver,String ip) {
if (weaver != null && weaver.equals(post.getWriter()))
return false;
Cache cache = cacheManager.getCache("push"); // 중복 추천 방지!
Element element = cache.get(post.getPostID()+"@@"+ip);
if (element == null || (element != null && element.getValue() == null)) {
post.push();
postDao.update(post);
Element newElement = new Element(post.getPostID()+"@@"+ip, ip);
cache.put(newElement);
return true;
}
return false;
}
示例5: push
import net.sf.ehcache.Element; //导入依赖的package包/类
/** 저장소를 추천하면 캐시에 저장하고 24시간 제한을 둠.
* @param repository
* @param weaver
* @param ip
* @return
*/
public boolean push(Repository repository, Weaver weaver,String ip) {
if(repository == null || repository.getAuthLevel() > 0 ||
(weaver == null && repository.isJoinWeaver(weaver)))
return false;
Cache cache = cacheManager.getCache("push");
Element element = cache.get(repository.getName()+"@@"+ip);
if (element == null || (element != null && element.getValue() == null)) {
repository.push();
repositoryDao.update(repository);
Element newElement = new Element(repository.getName()+"@@"+ip, ip);
cache.put(newElement);
return true;
}
return false;
}
示例6: get
import net.sf.ehcache.Element; //导入依赖的package包/类
@Override
public Object get(Object key) {
Element cacheEl = enCache.get(key);
if (cacheEl != null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(name + " hit cache ,key:" + key);
}
cacheStatistics.incHitTimes();
return cacheEl.getObjectValue();
} else {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(name + " miss cache ,key:" + key);
}
cacheStatistics.incAccessTimes();
return null;
}
}
示例7: get
import net.sf.ehcache.Element; //导入依赖的package包/类
/**
* Gets a value of an element which matches the given key.
* @param key the key of the element to return.
* @return The value placed into the cache with an earlier put, or null if not found or expired
* @throws CacheException
*/
public Object get(Object key) throws CacheException {
try {
if ( log.isDebugEnabled() ) {
log.debug("key: " + key);
}
if (key == null) {
return null;
}
else {
Element element = cache.get( (Serializable) key );
if (element == null) {
if ( log.isDebugEnabled() ) {
log.debug("Element for " + key + " is null");
}
return null;
}
else {
return element.getValue();
}
}
}
catch (net.sf.ehcache.CacheException e) {
throw new CacheException(e);
}
}
示例8: addCRL
import net.sf.ehcache.Element; //导入依赖的package包/类
@Override
protected boolean addCRL(final Object id, final X509CRL crl) {
try {
if (crl == null) {
logger.debug("No CRL was passed. Removing {} from cache...", id);
return this.crlCache.remove(id);
}
this.crlCache.put(new Element(id, crl.getEncoded()));
return this.crlCache.get(id) != null;
} catch (final Exception e) {
logger.warn("Failed to add the crl entry [{}] to the cache", crl);
throw new RuntimeException(e);
}
}
示例9: entrySet
import net.sf.ehcache.Element; //导入依赖的package包/类
@Override
public Set<Entry<String, String>> entrySet() {
final Set<String> keys = keySet();
final Set<Entry<String, String>> entries = new HashSet<>();
for (final String key : keys) {
final Element element = this.cache.get(key);
if (element != null) {
entries.add(new ElementMapEntry(element));
}
}
return entries;
}
示例10: verifyObserve
import net.sf.ehcache.Element; //导入依赖的package包/类
@Test
public void verifyObserve() throws Exception {
CacheStatus status = CacheStatus.class.cast(monitor.observe());
CacheStatistics stats = status.getStatistics()[0];
assertEquals(100, stats.getCapacity());
assertEquals(0, stats.getSize());
assertEquals(StatusCode.OK, status.getCode());
// Fill cache 95% full, which is above 10% free WARN threshold
IntStream.range(0, 95).forEach(i -> cache.put(new Element("key" + i, "value" + i)));
status = CacheStatus.class.cast(monitor.observe());
stats = status.getStatistics()[0];
assertEquals(100, stats.getCapacity());
assertEquals(95, stats.getSize());
assertEquals(StatusCode.WARN, status.getCode());
// Exceed the capacity and force evictions which should report WARN status
IntStream.range(95, 110).forEach(i -> cache.put(new Element("key" + i, "value" + i)));
status = CacheStatus.class.cast(monitor.observe());
stats = status.getStatistics()[0];
assertEquals(100, stats.getCapacity());
assertEquals(100, stats.getSize());
assertEquals(StatusCode.WARN, status.getCode());
}
示例11: idleExample
import net.sf.ehcache.Element; //导入依赖的package包/类
private void idleExample() throws InterruptedException {
System.out.println("\nIdle example\n");
Cache testCache = EhcacheHelper.createIdleCache(manager, "idleCache");
testCache.put(new Element(0, "String: 0"));
testCache.get(0);
System.out.println("Hit count: " + testCache.getStatistics().cacheHitCount());
System.out.println("Miss count: " + testCache.getStatistics().cacheMissCount());
Thread.sleep(TimeUnit.SECONDS.toMillis(EhcacheHelper.IDLE_TIME_SEC) - 1);
testCache.get(0);
System.out.println("Hit count: " + testCache.getStatistics().cacheHitCount());
System.out.println("Miss count: " + testCache.getStatistics().cacheMissCount());
Thread.sleep(TimeUnit.SECONDS.toMillis(EhcacheHelper.IDLE_TIME_SEC) + 1);
testCache.get(0);
System.out.println("Hit count: " + testCache.getStatistics().cacheHitCount());
System.out.println("Miss count: " + testCache.getStatistics().cacheMissCount());
}
示例12: exists
import net.sf.ehcache.Element; //导入依赖的package包/类
/**
* 判断缓存是否存在(根据缓存层级)
*/
public boolean exists(String name, String key, Level level) {
boolean flag = false;
if (level.equals(Level.Local)) {
if (this.ehcaches.containsKey(name)) {
Element element = this.getEhcache(name).get(key);
flag = element != null;
}
} else {
flag = this.jedisTemplate.exists(this.getRedisKeyOfElement(name, key));
}
if (logger.isDebugEnabled()) {
logger.debug("exists > name:" + name + ",key:" + key + ",level:" + level + ",exists:" + flag);
}
return flag;
}
示例13: get
import net.sf.ehcache.Element; //导入依赖的package包/类
@Override
public Object get(Object key) {
Element cacheEl = enCache.get(key);
if (cacheEl != null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(name+" hit cache ,key:" + key);
}
cacheStati.incHitTimes();
return cacheEl.getObjectValue();
} else {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(name+" miss cache ,key:" + key);
}
cacheStati.incAccessTimes();
return null;
}
}
示例14: changePassword
import net.sf.ehcache.Element; //导入依赖的package包/类
/** 인증된 키를 통해 재발급된 비밀번호로 변경하는 메서드
* @param email
* @param key
* @return 성공여부
*/
public boolean changePassword(String email,String key){
Cache rePasswordCache = cacheManager.getCache("repassword");
Element element = rePasswordCache.get(email);
if(element == null)
return false;
RePassword rePassword = (RePassword)element.getValue();
if(rePassword.getKey().equals(key)){
Weaver weaver = weaverDao.get(email);
weaver.setPassword(passwordEncoder.encodePassword(rePassword.getPassword(),null));
weaverDao.update(weaver);
}
return true;
}
示例15: getObjectID
import net.sf.ehcache.Element; //导入依赖的package包/类
public String getObjectID(String dataName,Weaver weaver){
Cache tmpNameCache = cacheManager.getCache("tmpName");
dataName = dataName.replace(" ", "_");
dataName = dataName.replace("?", "_");
dataName = dataName.replace("#", "_");
dataName = dataName.trim();
Element element = tmpNameCache.get(weaver.getId()+"/"+dataName);
if(element == null)
return "";
return (String)element.getValue();
}