Package ninja.cache

Class CacheMemcachedImpl

  • All Implemented Interfaces:
    Cache

    public class CacheMemcachedImpl
    extends Object
    implements Cache
    Memcached implementation (using http://code.google.com/p/spymemcached/) expiration is specified in seconds. Heavily inspired by excellent Play! 1.2.5 implementation.
    • Method Detail

      • add

        public void add​(String key,
                        Object value,
                        int expiration)
        Description copied from interface: Cache
        Add object to cache. Important: If the key exists already it won't be overwritten. Use set(...) instead. This method is fire and forget. Implementations may implement this async and non-blocking.
        Specified by:
        add in interface Cache
        Parameters:
        key - The key of the object to use for caching.
        value - The value of the object to add to the cache.
        expiration - Expiration time in seconds.
      • get

        public Object get​(String key)
        Description copied from interface: Cache
        Returns the object for this key or null if not found.
        Specified by:
        get in interface Cache
        Parameters:
        key - The key of the object to retrieve.
        Returns:
        The object of the key or null if not found.
      • clear

        public void clear()
        Description copied from interface: Cache
        Clear all values in cache.
        Specified by:
        clear in interface Cache
      • delete

        public void delete​(String key)
        Description copied from interface: Cache
        Delete key from cache.
        Specified by:
        delete in interface Cache
        Parameters:
        key - The key to delete.
      • get

        public Map<String,​Object> get​(String[] keys)
        Description copied from interface: Cache
        Returns all objects for the keys.
        Specified by:
        get in interface Cache
        Parameters:
        keys - The list of keys to retrieve from Cache.
        Returns:
        A map with key - object pairs that were found in cache.
      • incr

        public long incr​(String key,
                         int by)
        Description copied from interface: Cache
        Increments key by value.
        Specified by:
        incr in interface Cache
        Parameters:
        key - The key to increment
        by - Value by which to increment.
        Returns:
        New value of the key or -1 if key does not exist.
      • decr

        public long decr​(String key,
                         int by)
        Description copied from interface: Cache
        Decrements key by value.
        Specified by:
        decr in interface Cache
        Parameters:
        key - The key to decrement
        by - Value by which to decrement.
        Returns:
        New value of the key or -1 if key does not exist.
      • replace

        public void replace​(String key,
                            Object value,
                            int expiration)
        Description copied from interface: Cache
        Replaces key with new value. Important: Will do nothing if the key does not exist. This method is fire and forget. Implementations may implement this async and non-blocking.
        Specified by:
        replace in interface Cache
        Parameters:
        key - The key of the object to use for caching.
        value - The value of the object to replace in the cache.
        expiration - Expiration time in seconds.
      • safeAdd

        public boolean safeAdd​(String key,
                               Object value,
                               int expiration)
        Description copied from interface: Cache
        Similar to delete method. BUT it blocks until execution succeeds / fails AND wraps exceptions in a simple true / false return value
        Specified by:
        safeAdd in interface Cache
        Parameters:
        key - The key of the object to use for caching.
        value - The value of the object to add in the cache.
        expiration - Expiration time in seconds.
        Returns:
        true if add was successful, false if not.
      • safeDelete

        public boolean safeDelete​(String key)
        Description copied from interface: Cache
        Similar to delete method. BUT it blocks until execution succeeds / fails AND wraps exceptions in a simple true / false return value
        Specified by:
        safeDelete in interface Cache
        Parameters:
        key - The key to delete
        Returns:
        true if deletion was successful, false if not.
      • safeReplace

        public boolean safeReplace​(String key,
                                   Object value,
                                   int expiration)
        Description copied from interface: Cache
        Similar to delete method. BUT it blocks until execution succeeds / fails AND wraps exceptions in a simple true / false return value
        Specified by:
        safeReplace in interface Cache
        Parameters:
        key - The key of the object to use for caching.
        value - The value of the object to replace in the cache.
        expiration - Expiration time in seconds.
        Returns:
        true if replace was successful, false if not.
      • safeSet

        public boolean safeSet​(String key,
                               Object value,
                               int expiration)
        Description copied from interface: Cache
        Similar to delete method. BUT it blocks until execution succeeds / fails AND wraps exceptions in a simple true / false return value
        Specified by:
        safeSet in interface Cache
        Parameters:
        key - The key of the object to use for caching.
        value - The value of the object to set in the cache.
        expiration - Expiration time in seconds.
        Returns:
        true if set was successful, false if not.
      • set

        public void set​(String key,
                        Object value,
                        int expiration)
        Description copied from interface: Cache
        Adds object of cache. Important: This method potentially overwrites previously existing object with new values. This method is fire and forget. Implementations may implement this async and non-blocking.
        Specified by:
        set in interface Cache
        Parameters:
        key - The key of the object to use for caching.
        value - The value of the object to set in the cache.
        expiration - Expiration time in seconds.
      • stop

        public void stop()