@Override public void getBytes(final Callback<Optional<byte[]>> callback, final String key) { final CacheEntry cacheEntry = localCache.get(key); if (cacheEntry == null) { callback.resolve(Optional.<byte[]>empty()); return; } if (cacheEntry.isExpired(time)) { localCache.remove(key); callback.resolve(Optional.<byte[]>empty()); } else { final byte[] value = ((CacheBytesEntry) cacheEntry).value; if (value == null) { callback.resolve(Optional.<byte[]>empty()); } else { callback.resolve(Optional.of(value)); } } }
@Override public void getString(final Callback<Optional<String>> callback, final String key) { final CacheEntry cacheEntry = localCache.get(key); if (cacheEntry == null) { callback.resolve(Optional.<String>empty()); return; } if (cacheEntry.isExpired(time)) { localCache.remove(key); callback.resolve(Optional.<String>empty()); } else { final String value = ((CacheStringEntry) cacheEntry).value; if (value == null) { callback.resolve(Optional.<String>empty()); } else { callback.resolve(Optional.of(value)); } } }
private CacheEntry<T> doGetCacheEntry(final Callback<Optional<T>> callback, final String key) { CacheEntry<T> cacheEntry = cache.get(key); if (cacheEntry != null) { if (cacheEntry.isExpired(time)) { statsCollector.increment(statKey + "expire"); cache.remove(key); //do not return so we can look things up in the fallbackReader. return null; } else { final T value = cacheEntry.getValue(); if (value == null) { callback.resolve(Optional.<T>empty()); } else { statsCollector.increment(statKey + "cacheHit"); callback.resolve(Optional.of(value)); } } } return cacheEntry; }
public CharBuf addBigDecimal( BigDecimal key ) { if (bigDCache == null) { bigDCache = new SimpleLRUCache<> ( 100 ); } char [] chars = bigDCache.get ( key ); if ( chars == null ) { String str = key.toString(); chars = FastStringUtils.toCharArray ( str ); bigDCache.put ( key, chars ); } add ( chars ); return this; }
public final CharBuf addFloat( Float key ) { if (fcache == null) { fcache = new SimpleLRUCache<> ( 100 ); } char [] chars = fcache.get ( key ); if ( chars == null ) { String str = Float.toString ( key ); chars = FastStringUtils.toCharArray ( str ); fcache.put ( key, chars ); } add ( chars ); return this; }
public CharBuf addBigInteger( BigInteger key ) { if (bigICache == null) { bigICache = new SimpleLRUCache<> ( 100 ); } char [] chars = bigICache.get ( key ); if ( chars == null ) { String str = key.toString(); chars = FastStringUtils.toCharArray ( str ); bigICache.put ( key, chars ); } add ( chars ); return this; }
public final CharBuf addLong( Long key ) { if (lcache == null) { lcache = new SimpleLRUCache<> ( 100 ); } char [] chars = lcache.get ( key ); if ( chars == null ) { String str = Long.toString ( key ); chars = FastStringUtils.toCharArray ( str ); lcache.put ( key, chars ); } add ( chars ); return this; }
public final CharBuf addInt( Integer key ) { if (icache == null) { icache = new SimpleLRUCache<> ( 1000 ); } char [] chars = icache.get ( key ); if ( chars == null ) { String str = Integer.toString ( key ); chars = FastStringUtils.toCharArray ( str ); icache.put ( key, chars ); } addChars ( chars ); return this; }
public CharBuf addBigInteger( BigInteger key ) { if (bigICache == null) { bigICache = new SimpleLRUCache<> ( 100 ); } char [] chars = bigICache.get ( key ); if ( chars == null ) { String str = key.toString(); chars = FastStringUtils.toCharArray ( str ); bigICache.put ( key, chars ); } add ( chars ); return this; }
public final CharBuf addLong( Long key ) { if (lcache == null) { lcache = new SimpleLRUCache<> ( 100 ); } char [] chars = lcache.get ( key ); if ( chars == null ) { String str = Long.toString ( key ); chars = FastStringUtils.toCharArray ( str ); lcache.put ( key, chars ); } add ( chars ); return this; }
public final CharBuf addFloat( Float key ) { if (fcache == null) { fcache = new SimpleLRUCache<> ( 100 ); } char [] chars = fcache.get ( key ); if ( chars == null ) { String str = Float.toString ( key ); chars = FastStringUtils.toCharArray ( str ); fcache.put ( key, chars ); } add ( chars ); return this; }
public CharBuf addBigDecimal( BigDecimal key ) { if (bigDCache == null) { bigDCache = new SimpleLRUCache<> ( 100 ); } char [] chars = bigDCache.get ( key ); if ( chars == null ) { String str = key.toString(); chars = FastStringUtils.toCharArray ( str ); bigDCache.put ( key, chars ); } add ( chars ); return this; }
public final CharBuf addDouble( Double key ) { if (dcache == null) { dcache = new SimpleLRUCache<> ( 100 ); } char [] chars = dcache.get ( key ); if ( chars == null ) { String str = Double.toString ( key ); chars = FastStringUtils.toCharArray ( str ); dcache.put ( key, chars ); } add ( chars ); return this; }
public final CharBuf addInt( Integer key ) { if (icache == null) { icache = new SimpleLRUCache<> ( 1000 ); } char [] chars = icache.get ( key ); if ( chars == null ) { String str = Integer.toString ( key ); chars = FastStringUtils.toCharArray ( str ); icache.put ( key, chars ); } addChars ( chars ); return this; }
public final CharBuf addDouble( Double key ) { if (dcache == null) { dcache = new SimpleLRUCache<> ( 100 ); } char [] chars = dcache.get ( key ); if ( chars == null ) { String str = Double.toString ( key ); chars = FastStringUtils.toCharArray ( str ); dcache.put ( key, chars ); } add ( chars ); return this; }
public CharBuf addCurrency( Currency key ) { if (currencyCache == null) { currencyCache = new SimpleLRUCache<> ( 100 ); } char [] chars = currencyCache.get ( key ); if ( chars == null ) { String str = '"' + key.toString() + '"'; chars = FastStringUtils.toCharArray ( str ); currencyCache.put ( key, chars ); } add ( chars ); return this; }
public CharBuf addCurrency( Currency key ) { if (currencyCache == null) { currencyCache = new SimpleLRUCache<> ( 100 ); } char [] chars = currencyCache.get ( key ); if ( chars == null ) { String str = '"' + key.toString() + '"'; chars = FastStringUtils.toCharArray ( str ); currencyCache.put ( key, chars ); } add ( chars ); return this; }
@Override public final void serializeDate( JsonSerializerInternal jsonSerializer, Date date, CharBuf builder ) { String string = dateCache.get ( date ); if ( string == null) { CharBuf buf = CharBuf.create ( Dates.JSON_TIME_LENGTH ); Dates.jsonDateChars ( calendar, date, buf ); string = buf.toString(); dateCache.put ( date, string ); } builder.addChars ( FastStringUtils.toCharArray( string ) ); } }
@Override public final void serializeDate( JsonSerializerInternal jsonSerializer, Date date, CharBuf builder ) { String string = dateCache.get ( date ); if ( string == null) { CharBuf buf = CharBuf.create ( Dates.JSON_TIME_LENGTH ); Dates.jsonDateChars ( calendar, date, buf ); string = buf.toString(); dateCache.put ( date, string ); } builder.addChars ( FastStringUtils.toCharArray( string ) ); } }
@Override public final void serializeDate( JsonSerializerInternal jsonSerializer, Date date, CharBuf builder ) { String string = dateCache.get ( date ); if ( string == null) { CharBuf buf = CharBuf.create ( Dates.JSON_TIME_LENGTH ); Dates.jsonDateChars ( calendar, date, buf ); string = buf.toString(); dateCache.put ( date, string ); } builder.addChars ( FastStringUtils.toCharArray( string ) ); } }