com.thimbleware.jmemcached
Class CacheImpl

java.lang.Object
  extended by com.thimbleware.jmemcached.AbstractCache<LocalCacheElement>
      extended by com.thimbleware.jmemcached.CacheImpl
All Implemented Interfaces:
Cache<LocalCacheElement>

public final class CacheImpl
extends AbstractCache<LocalCacheElement>
implements Cache<LocalCacheElement>

Default implementation of the cache handler, supporting local memory cache elements.


Nested Class Summary
protected static class CacheImpl.DelayedMCElement
          Delayed key blocks get processed occasionally.
 
Nested classes/interfaces inherited from interface com.thimbleware.jmemcached.Cache
Cache.DeleteResponse, Cache.StoreResponse
 
Field Summary
 
Fields inherited from class com.thimbleware.jmemcached.AbstractCache
casCounter, getCmds, getHits, getMisses, setCmds, started
 
Constructor Summary
CacheImpl(CacheStorage<Key,LocalCacheElement> storage)
           
 
Method Summary
 Cache.StoreResponse add(LocalCacheElement e)
          Add an element to the cache
 Cache.StoreResponse append(LocalCacheElement element)
          Append bytes to the end of an element in the cache
 void asyncEventPing()
          Called periodically by the network event loop to process any pending events.
 Cache.StoreResponse cas(java.lang.Long cas_key, LocalCacheElement e)
          Set an element in the cache but only if the element has not been touched since the last 'gets'
 void close()
          Close the cache, freeing all resources on which it depends.
 Cache.DeleteResponse delete(Key key, int time)
          Handle the deletion of an item from the cache.
 boolean flush_all()
          Flush all cache entries
 boolean flush_all(int expire)
          Flush all cache entries with a timestamp after a given expiration time
 java.lang.Integer get_add(Key key, int mod)
          Increment/decremen t an (integer) element in the cache
 LocalCacheElement[] get(Key... keys)
          Get element(s) from the cache
 long getCurrentBytes()
           
 long getCurrentItems()
           
 long getLimitMaxBytes()
           
protected  boolean isBlocked(CacheElement e)
           
protected  boolean isExpired(CacheElement e)
           
protected  java.util.Set<Key> keys()
           
 Cache.StoreResponse prepend(LocalCacheElement element)
          Prepend bytes to the end of an element in the cache
 Cache.StoreResponse replace(LocalCacheElement e)
          Replace an element in the cache
 Cache.StoreResponse set(LocalCacheElement e)
          Set an element in the cache
 
Methods inherited from class com.thimbleware.jmemcached.AbstractCache
getGetCmds, getGetHits, getGetMisses, getSetCmds, initStats, Now, stat
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.thimbleware.jmemcached.Cache
getGetCmds, getGetHits, getGetMisses, getSetCmds, stat
 

Constructor Detail

CacheImpl

public CacheImpl(CacheStorage<Key,LocalCacheElement> storage)
Method Detail

delete

public Cache.DeleteResponse delete(Key key,
                                   int time)
Description copied from interface: Cache
Handle the deletion of an item from the cache.

Specified by:
delete in interface Cache<LocalCacheElement>
Parameters:
key - the key for the item
time - an amount of time to block this entry in the cache for further writes
Returns:
the message response

add

public Cache.StoreResponse add(LocalCacheElement e)
Description copied from interface: Cache
Add an element to the cache

Specified by:
add in interface Cache<LocalCacheElement>
Parameters:
e - the element to add
Returns:
the store response code

replace

public Cache.StoreResponse replace(LocalCacheElement e)
Description copied from interface: Cache
Replace an element in the cache

Specified by:
replace in interface Cache<LocalCacheElement>
Parameters:
e - the element to replace
Returns:
the store response code

append

public Cache.StoreResponse append(LocalCacheElement element)
Description copied from interface: Cache
Append bytes to the end of an element in the cache

Specified by:
append in interface Cache<LocalCacheElement>
Parameters:
element - the element to append
Returns:
the store response code

prepend

public Cache.StoreResponse prepend(LocalCacheElement element)
Description copied from interface: Cache
Prepend bytes to the end of an element in the cache

Specified by:
prepend in interface Cache<LocalCacheElement>
Parameters:
element - the element to append
Returns:
the store response code

set

public Cache.StoreResponse set(LocalCacheElement e)
Description copied from interface: Cache
Set an element in the cache

Specified by:
set in interface Cache<LocalCacheElement>
Parameters:
e - the element to set
Returns:
the store response code

cas

public Cache.StoreResponse cas(java.lang.Long cas_key,
                               LocalCacheElement e)
Description copied from interface: Cache
Set an element in the cache but only if the element has not been touched since the last 'gets'

Specified by:
cas in interface Cache<LocalCacheElement>
Parameters:
cas_key - the cas key returned by the last gets
e - the element to set
Returns:
the store response code

get_add

public java.lang.Integer get_add(Key key,
                                 int mod)
Description copied from interface: Cache
Increment/decremen t an (integer) element in the cache

Specified by:
get_add in interface Cache<LocalCacheElement>
Parameters:
key - the key to increment
mod - the amount to add to the value
Returns:
the message response

isBlocked

protected boolean isBlocked(CacheElement e)

isExpired

protected boolean isExpired(CacheElement e)

get

public LocalCacheElement[] get(Key... keys)
Description copied from interface: Cache
Get element(s) from the cache

Specified by:
get in interface Cache<LocalCacheElement>
Parameters:
keys - the key for the element to lookup
Returns:
the element, or 'null' in case of cache miss.

flush_all

public boolean flush_all()
Description copied from interface: Cache
Flush all cache entries

Specified by:
flush_all in interface Cache<LocalCacheElement>
Returns:
command response

flush_all

public boolean flush_all(int expire)
Description copied from interface: Cache
Flush all cache entries with a timestamp after a given expiration time

Specified by:
flush_all in interface Cache<LocalCacheElement>
Parameters:
expire - the flush time in seconds
Returns:
command response

close

public void close()
           throws java.io.IOException
Description copied from interface: Cache
Close the cache, freeing all resources on which it depends.

Specified by:
close in interface Cache<LocalCacheElement>
Throws:
java.io.IOException

keys

protected java.util.Set<Key> keys()
Specified by:
keys in class AbstractCache<LocalCacheElement>

getCurrentItems

public long getCurrentItems()
Specified by:
getCurrentItems in interface Cache<LocalCacheElement>
Specified by:
getCurrentItems in class AbstractCache<LocalCacheElement>
Returns:
the # of items in the cache

getLimitMaxBytes

public long getLimitMaxBytes()
Specified by:
getLimitMaxBytes in interface Cache<LocalCacheElement>
Specified by:
getLimitMaxBytes in class AbstractCache<LocalCacheElement>
Returns:
the maximum size of the cache (in bytes)

getCurrentBytes

public long getCurrentBytes()
Specified by:
getCurrentBytes in interface Cache<LocalCacheElement>
Specified by:
getCurrentBytes in class AbstractCache<LocalCacheElement>
Returns:
the current cache usage (in bytes)

asyncEventPing

public void asyncEventPing()
Description copied from interface: Cache
Called periodically by the network event loop to process any pending events. (such as delete queues, etc.)

Specified by:
asyncEventPing in interface Cache<LocalCacheElement>
Specified by:
asyncEventPing in class AbstractCache<LocalCacheElement>


Copyright © 2008-2011 ThimbleWare. All Rights Reserved.