Java Code Examples for net.sf.ehcache.Element#getValue()

The following examples show how to use net.sf.ehcache.Element#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EhCacheFacade.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Retrieves an object stored under the given key from the cache specified in
 * the given caching model. The caching model should be an instance of
 * <code>{@link EhCacheCachingModel}</code>.
 *
 * @param key   the key of the cache entry
 * @param model the caching model
 * @return the object retrieved from the cache. Can be <code>null</code>.
 * @throws CacheNotFoundException if the cache specified in the given model cannot be found.
 * @throws CacheAccessException   wrapping any unexpected exception thrown by the cache.
 * @see AbstractCacheProviderFacade#onGetFromCache(Serializable,CachingModel)
 */
protected Object onGetFromCache(Serializable key, CachingModel model)
		throws CacheException {
	Ehcache cache = getCache(model);
	Object cachedObject = null;

	try {
		Element cacheElement = cache.get(key);
		if (cacheElement != null) {
			cachedObject = cacheElement.getValue();
		}

	} catch (Exception exception) {
		throw new CacheAccessException(exception);
	}

	return cachedObject;
}
 
Example 2
Source File: NamespaceManager.java    From rya with Apache License 2.0 6 votes vote down vote up
public String getNamespace(String pfx) {
    //try in the cache first
    Element element = namespaceCache.get(pfx);
    if (element != null) {
        return (String) element.getValue();
    }

    try {
        String namespace = namespaceManager.getNamespace(pfx);
        if (namespace != null) {
            namespaceCache.put(new Element(pfx, namespace));
            return namespace;
        }
    } catch (Exception e) {
        //TODO: print or log?
    }
    return null;

}
 
Example 3
Source File: EHResourceFactoryCache.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Resource getInternal( final ResourceKey key, final Class target ) {
  try {
    final Element element = factoryCache.get( new CompoundCacheKey( key, target ) );
    if ( element != null ) {
      final Resource resource = (Resource) element.getObjectValue();
      if ( resource != null ) {
        return resource;
      }
      final Resource resource1 = (Resource) element.getValue();
      if ( resource1 != null ) {
        return resource1;
      }
      return null;
    } else {
      return null;
    }
  } catch ( CacheException e ) {
    if ( logger.isDebugEnabled() ) {
      logger.debug( "Failed to retrieve resource for key " + key, e );
    }
    return null;
  }
}
 
Example 4
Source File: CmsSiteFlowMngImpl.java    From Lottery with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public int freshCacheToDB(Ehcache cache) {
	int count = 0;
	List<String> list = cache.getKeys();
	for (String uuid : list) {
		Element element = cache.get(uuid);
		if (element == null) {
			return count;
		}
		CmsSiteFlow cmsSiteFlow = (CmsSiteFlow) element.getValue();
		if (cmsSiteFlow.getId() == null
				&& cmsSiteFlow.getSessionId() != null) {
			dao.save(cmsSiteFlow);
		}
	}
	return count;
}
 
Example 5
Source File: ContentCountCacheImpl.java    From Lottery with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @see ContentCountCache#viewAndGet(Integer)
 */
public int[] viewAndGet(Integer id) {
	ContentCount count = contentCountMng.findById(id);
	if (count == null) {
		return null;
	}
	Element e = cache.get(id);
	Integer views;
	if (e != null) {
		views = (Integer) e.getValue() + 1;
	} else {
		views = 1;
	}
	cache.put(new Element(id, views));
	refreshToDB();
	return new int[] { views + count.getViews(), count.getComments(),
			count.getDownloads(), count.getUps(), count.getDowns() };
}
 
Example 6
Source File: EhCache.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
public Object get(Object key) {
	Element element = getEhCache().get(key);
	if (element != null) {
		return element.getValue();
	}
	
	return null;
}
 
Example 7
Source File: EhCache.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Override
protected V getElement(String key) {
	Element element = cache.get(key);
	if (element==null) {
		return null;
	}
	return (V)element.getValue();
}
 
Example 8
Source File: RoleDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
private Role getFromCache(String key) {
	logger.debug("IN");
	String tenantId = this.getTenant();
	Role role = null;
	if (tenantId != null) {
		// The tenant is set, so let's find it into the cache
		String cacheName = tenantId + DEFAULT_CACHE_SUFFIX;
		try {
			if (cacheManager == null) {
				cacheManager = CacheManager.create();
				logger.debug("Cache for tenant " + tenantId + "does not exist yet. Nothing to get.");
				logger.debug("OUT");
				return null;
			} else {
				if (!cacheManager.cacheExists(cacheName)) {
					logger.debug("Cache for tenant " + tenantId + "does not exist yet. Nothing to get.");
					logger.debug("OUT");
					return null;
				} else {
					Element el = cacheManager.getCache(cacheName).get(key);
					if (el != null) {
						role = (Role) el.getValue();
					}
				}
			}
		} catch (Throwable t) {
			throw new SpagoBIRuntimeException("Error while getting a Role cache item with key " + key + " for tenant " + tenantId, t);
		}
	}
	logger.debug("OUT");
	return role;
}
 
Example 9
Source File: LowFunctionalityDAOHibImpl.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
private LowFunctionality getFromCache(String key) {
	logger.debug("IN");
	String tenantId = this.getTenant();
	LowFunctionality funct = null;
	if (tenantId != null) {
		// The tenant is set, so let's find it into the cache
		String cacheName = tenantId + DEFAULT_CACHE_SUFFIX;
		try {
			if (cacheManager == null) {
				cacheManager = CacheManager.create();
				logger.debug("Cache for tenant " + tenantId + "does not exist yet. Nothing to get.");
				logger.debug("OUT");
				return null;
			} else {
				if (!cacheManager.cacheExists(cacheName)) {
					logger.debug("Cache for tenant " + tenantId + "does not exist yet. Nothing to get.");
					logger.debug("OUT");
					return null;
				} else {
					Element el = cacheManager.getCache(cacheName).get(key);
					if (el != null) {
						funct = (LowFunctionality) el.getValue();
					}
				}
			}
		} catch (Throwable t) {
			throw new SpagoBIRuntimeException("Error while getting a LowFunctionality cache item with key " + key + " for tenant " + tenantId, t);
		}
	}
	logger.debug("OUT");
	return funct;
}
 
Example 10
Source File: DPSArchive.java    From webcurator with Apache License 2.0 5 votes vote down vote up
private static DepData[] getProducerDataFromCache(String producerAgentUserId) {
    try {
        if (producerCache == null) return null;
        Element cacheElement;
        synchronized (producerCache) {
            cacheElement = producerCache.get(producerAgentUserId);
        }
        if (cacheElement == null) return null;
        return (DepData[]) cacheElement.getValue();
    } catch (Exception e) {
        log.warn("Error getting producer data from cache for the producer agent " + producerAgentUserId, e);
        return null;
    }
}
 
Example 11
Source File: SimpleSlidingAverageThrottlingServiceImpl.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
private LimitMeter getMeter(String user) throws IllegalStateException, CacheException {
	Element element = cache.get(user);
	if (element == null) {
		LimitMeter limitMeter = createMeter(user);
		cache.put(new Element(user, limitMeter));
		return limitMeter;
	}
	return (LimitMeter) element.getValue();
}
 
Example 12
Source File: ContentCountDaoImpl.java    From Lottery with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public int freshCacheToDB(Ehcache cache) {
	List<Integer> keys = cache.getKeys();
	if (keys.size() <= 0) {
		return 0;
	}
	Element e;
	Integer views;
	int i = 0;
	String hql = "update ContentCount bean"
			+ " set bean.views=bean.views+:views"
			+ ",bean.viewsMonth=bean.viewsMonth+:views"
			+ ",bean.viewsWeek=bean.viewsWeek+:views"
			+ ",bean.viewsDay=bean.viewsDay+:views" + " where bean.id=:id";
	Query query = getSession().createQuery(hql);
	for (Integer id : keys) {
		e = cache.get(id);
		if (e != null) {
			views = (Integer) e.getValue();
			if (views != null) {
				query.setParameter("views", views);
				query.setParameter("id", id);
				i += query.executeUpdate();
			}
		}
	}
	return i;
}
 
Example 13
Source File: EhCacheImpl.java    From restcommander with Apache License 2.0 4 votes vote down vote up
public Object get(String key) {
    Element e = cache.get(key);
    return (e == null) ? null : e.getValue();
}
 
Example 14
Source File: EhcacheSessionCache.java    From Lottery with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public Map<String, Serializable> getSession(String root) {
	Element e = cache.get(root);
	return e != null ? (HashMap<String, Serializable>) e.getValue() : null;
}
 
Example 15
Source File: EhCacheBackedMapImpl.java    From openregistry with Apache License 2.0 4 votes vote down vote up
public V get(Object key) {
    final Element element = this.cache.get(key);

    return element == null ? null : (V) element.getValue();
}
 
Example 16
Source File: EhcacheBackedMap.java    From cas4.0.x-server-wechat with Apache License 2.0 4 votes vote down vote up
@Override
public String get(final Object key) {
    final Element element = this.cache.get(key);

    return element == null ? null : (String) element.getValue();
}
 
Example 17
Source File: EhcacheBackedMap.java    From springboot-shiro-cas-mybatis with MIT License 4 votes vote down vote up
@Override
public String get(final Object key) {
    final Element element = this.cache.get(key);

    return element == null ? null : (String) element.getValue();
}