com.avaje.ebean.cache
Interface ServerCache


public interface ServerCache

Represents part of the "L2" server side cache.

This is used to cache beans or query results (bean collections).

There are 2 ServerCache's for each bean type. One is used as the 'bean cache' which holds beans of a given type. The other is the 'query cache' holding query results for a given type.

Author:
rbygrave

Method Summary
 void clear()
          Clear all entries from the cache.
 Object get(Object id)
          Return the value given the key.
 int getHitRatio()
          Return the hit ratio the cache is currently getting.
 ServerCacheOptions getOptions()
          Return the configuration options for this cache.
 ServerCacheStatistics getStatistics(boolean reset)
          Return statistics for the cache.
 void init(EbeanServer ebeanServer)
          Just after a cache is created this init method is called.
 Object put(Object id, Object value)
          Put the value in the cache with a given id.
 Object putIfAbsent(Object id, Object value)
          Put the value in the cache but only if a matching value is not already in the cache.
 Object remove(Object id)
          Remove a entry from the cache given its id.
 void setOptions(ServerCacheOptions options)
          Update the configuration options for this cache.
 int size()
          Return the number of entries in the cache.
 

Method Detail

init

void init(EbeanServer ebeanServer)
Just after a cache is created this init method is called. This is so that a cache implementation can make use of the BackgroundExecutor service to trim/cleanup itself or use the EbeanServer to populate itself.

This method is called after the cache is constructed but before the cache is made available for use.


getOptions

ServerCacheOptions getOptions()
Return the configuration options for this cache.


setOptions

void setOptions(ServerCacheOptions options)
Update the configuration options for this cache.


get

Object get(Object id)
Return the value given the key.


put

Object put(Object id,
           Object value)
Put the value in the cache with a given id.


putIfAbsent

Object putIfAbsent(Object id,
                   Object value)
Put the value in the cache but only if a matching value is not already in the cache.


remove

Object remove(Object id)
Remove a entry from the cache given its id.


clear

void clear()
Clear all entries from the cache.

NOTE: Be careful using this method in that most of the time application code should clear BOTH the bean and query caches at the same time. This can be done via ServerCacheManager.clear(Class).


size

int size()
Return the number of entries in the cache.


getHitRatio

int getHitRatio()
Return the hit ratio the cache is currently getting.


getStatistics

ServerCacheStatistics getStatistics(boolean reset)
Return statistics for the cache.

Parameters:
reset - if true the statistics are reset.


Copyright © 2010. All Rights Reserved.