@Override public StoreEntry create(Long key, int timeToLive) { StoreEntryImpl result = new StoreEntryImpl(timeToLive); Element element = new Element(key, result); element.setTimeToLive(timeToLive); cache.put(element); return result; }
@Override public StoreEntry get(Long key) { Element entry = null; try { /* This may block. */ entry = cache.get(key); } catch (LockTimeoutException e) { throw new RuntimeException(); } catch (RuntimeException e) { /* Release the lock that may have been acquired. */ cache.put(new Element(key, null)); } StoreEntry result = null; if (entry != null) { /* * We don't need to check isExpired() on the result, since ehcache takes care of expiring entries for us. * c.f. the get(Key) implementation in this class. */ result = (StoreEntry)entry.getObjectValue(); } return result; }
@Override public void put(Object key, Object value) { final Element element = new Element(key, value); ehcache.put(element); }
@Override public void put(Object key, Object value, int timeToLiveInSeconds) { final Element element = new Element(key, value); element.setTimeToLive(timeToLiveInSeconds); ehcache.put(element); }
/** * {@inheritDoc} */ public StoreEntry get(Key key) { Element entry = null; try { /* This may block. */ entry = cache.get(key); } catch (LockTimeoutException e) { throw new RuntimeException(); } catch (RuntimeException e) { /* Release the lock that may have been acquired. */ cache.put(new Element(key, null)); } StoreEntry result = null; if (entry != null) { /* * We don't need to check isExpired() on the result, since ehcache takes care of expiring entries for us. * c.f. the get(Key) implementation in this class. */ result = (StoreEntry) entry.getObjectValue(); } return result; }
/** * {@inheritDoc} */ public StoreEntry create(Key key, int timeToLive) { StoreEntryImpl result = new StoreEntryImpl(timeToLive); Element element = new Element(key, result); element.setTimeToLive(timeToLive); cache.put(element); return result; }
/** * Add a new entry to the cache. * * @param key name to be used for the entry. * @param value object that is stored. * @throws CacheException in the event ehcache throws an exception it will be wrapped. */ @Override public void put( Object key, Object value ) throws CacheException { if ( cache == null ) { String error = "put detected null cache name [" + name + "]"; throw new CacheException( GlobalErrIds.FT_NULL_CACHE, error ); } try { cache.put( new Element( key, value ) ); } catch ( net.sf.ehcache.CacheException ce ) { String error = "put cache name [" + name + "] key [" + key + "] caught CacheException=" + ce.getMessage(); throw new CacheException( GlobalErrIds.FT_CACHE_PUT_ERR, error, ce ); } }