play.cache

## Class Cache

- java.lang.Object
- - play.cache.Cache

    public abstract class Cache
    extends java.lang.Object

The Cache. Mainly an interface to memcached or EhCache. Note: When specifying expiration == "0s" (zero seconds) the actual expiration-time may vary between different cache implementations

### Field Summary

Fields
`static CacheImpl` `cacheImpl` The underlying cache implementation
`static CacheImpl` `forcedCacheImpl` Sometime we REALLY need to change the implementation :)

### Constructor Summary

Constructors
Constructor and Description
`Cache()`

### Method Summary

All Methods Static Methods Concrete Methods
`static void` `add(java.lang.String key, java.lang.Object value)` Add an element only if it doesn't exist and store it indefinitely.
`static void` `add(java.lang.String key, java.lang.Object value, java.lang.String expiration)` Add an element only if it doesn't exist.
`static void` `clear()` Clear all data from cache.
`static long` `decr(java.lang.String key)` Decrement the element value (must be a Number) by 1.
`static long` `decr(java.lang.String key, int by)` Decrement the element value (must be a Number).
`static void` `delete(java.lang.String key)` Delete an element from the cache.
`static java.util.Map<java.lang.String,java.lang.Object>` `get(java.lang.String... key)` Bulk retrieve.
`static java.lang.Object` `get(java.lang.String key)` Retrieve an object.
`static <T> T` `get(java.lang.String key, java.lang.Class<T> clazz)` Convenient clazz to get a value a class type;
`static long` `incr(java.lang.String key)` Increment the element value (must be a Number) by 1.
`static long` `incr(java.lang.String key, int by)` Increment the element value (must be a Number).
`static void` `init()` Initialize the cache system.
`static void` `replace(java.lang.String key, java.lang.Object value)` Replace an element only if it already exists and store it indefinitely.
`static void` `replace(java.lang.String key, java.lang.Object value, java.lang.String expiration)` Replace an element only if it already exists.
`static boolean` `safeAdd(java.lang.String key, java.lang.Object value, java.lang.String expiration)` Add an element only if it doesn't exist, and return only when the element is effectively cached.
`static boolean` `safeDelete(java.lang.String key)` Delete an element from the cache and return only when the element is effectively removed.
`static boolean` `safeReplace(java.lang.String key, java.lang.Object value, java.lang.String expiration)` Replace an element only if it already exists and return only when the element is effectively cached.
`static boolean` `safeSet(java.lang.String key, java.lang.Object value, java.lang.String expiration)` Set an element and return only when the element is effectively cached.
`static void` `set(java.lang.String key, java.lang.Object value)` Set an element and store it indefinitely.
`static void` `set(java.lang.String key, java.lang.Object value, java.lang.String expiration)` Set an element.
`static void` `stop()` Stop the cache system.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### cacheImpl

    public static CacheImpl cacheImpl

The underlying cache implementation

#### forcedCacheImpl

    public static CacheImpl forcedCacheImpl

Sometime we REALLY need to change the implementation :)

### Constructor Detail

#### Cache

    public Cache()

### Method Detail

#### add

    public static void add(java.lang.String key,
                           java.lang.Object value,
                           java.lang.String expiration)

Add an element only if it doesn't exist.

Parameters:
  `key` - Element key
  `value` - Element value
  `expiration` - Ex: 10s, 3mn, 8h

#### safeAdd

    public static boolean safeAdd(java.lang.String key,
                                  java.lang.Object value,
                                  java.lang.String expiration)

Add an element only if it doesn't exist, and return only when the element is effectively cached.

Parameters:
  `key` - Element key
  `value` - Element value
  `expiration` - Ex: 10s, 3mn, 8h
Returns:
  If the element an eventually been cached

#### add

    public static void add(java.lang.String key,
                           java.lang.Object value)

Add an element only if it doesn't exist and store it indefinitely.

Parameters:
  `key` - Element key
  `value` - Element value

#### set

    public static void set(java.lang.String key,
                           java.lang.Object value,
                           java.lang.String expiration)

Set an element.

Parameters:
  `key` - Element key
  `value` - Element value
  `expiration` - Ex: 10s, 3mn, 8h

#### safeSet

    public static boolean safeSet(java.lang.String key,
                                  java.lang.Object value,
                                  java.lang.String expiration)

Set an element and return only when the element is effectively cached.

Parameters:
  `key` - Element key
  `value` - Element value
  `expiration` - Ex: 10s, 3mn, 8h
Returns:
  If the element an eventually been cached

#### set

    public static void set(java.lang.String key,
                           java.lang.Object value)

Set an element and store it indefinitely.

Parameters:
  `key` - Element key
  `value` - Element value

#### replace

    public static void replace(java.lang.String key,
                               java.lang.Object value,
                               java.lang.String expiration)

Replace an element only if it already exists.

Parameters:
  `key` - Element key
  `value` - Element value
  `expiration` - Ex: 10s, 3mn, 8h

#### safeReplace

    public static boolean safeReplace(java.lang.String key,
                                      java.lang.Object value,
                                      java.lang.String expiration)

Replace an element only if it already exists and return only when the element is effectively cached.

Parameters:
  `key` - Element key
  `value` - Element value
  `expiration` - Ex: 10s, 3mn, 8h
Returns:
  If the element an eventually been cached

#### replace

    public static void replace(java.lang.String key,
                               java.lang.Object value)

Replace an element only if it already exists and store it indefinitely.

Parameters:
  `key` - Element key
  `value` - Element value

#### incr

    public static long incr(java.lang.String key,
                            int by)

Increment the element value (must be a Number).

Parameters:
  `key` - Element key
  `by` - The incr value
Returns:
  The new value

#### incr

    public static long incr(java.lang.String key)

Increment the element value (must be a Number) by 1.

Parameters:
  `key` - Element key
Returns:
  The new value

#### decr

    public static long decr(java.lang.String key,
                            int by)

Decrement the element value (must be a Number).

Parameters:
  `key` - Element key
  `by` - The decr value
Returns:
  The new value

#### decr

    public static long decr(java.lang.String key)

Decrement the element value (must be a Number) by 1.

Parameters:
  `key` - Element key
Returns:
  The new value

#### get

    public static java.lang.Object get(java.lang.String key)

Retrieve an object.

Parameters:
  `key` - The element key
Returns:
  The element value or null

#### get

    public static java.util.Map<java.lang.String,java.lang.Object> get(java.lang.String... key)

Bulk retrieve.

Parameters:
  `key` - List of keys
Returns:
  Map of keys & values

#### delete

    public static void delete(java.lang.String key)

Delete an element from the cache.

Parameters:
  `key` - The element key

#### safeDelete

    public static boolean safeDelete(java.lang.String key)

Delete an element from the cache and return only when the element is effectively removed.

Parameters:
  `key` - The element key
Returns:
  If the element an eventually been deleted

#### clear

    public static void clear()

Clear all data from cache.

#### get

    public static <T> T get(java.lang.String key,
                            java.lang.Class<T> clazz)

Convenient clazz to get a value a class type;

Type Parameters:
  `T` - The needed type
Parameters:
  `key` - The element key
  `clazz` - The type class
Returns:
  The element value or null

#### init

    public static void init()

Initialize the cache system.

#### stop

    public static void stop()

Stop the cache system.