Class MockCache

  • All Implemented Interfaces:
    Cache

    @Singleton
    public class MockCache
    extends Object
    implements Cache
    Author:
    Alex Bogdanovski [alex@erudika.com]
    • Constructor Detail

      • MockCache

        public MockCache()
    • Method Detail

      • contains

        public boolean contains​(String appid,
                                String id)
        Description copied from interface: Cache
        Do we have this object in the cache?
        Specified by:
        contains in interface Cache
        Parameters:
        appid - the name of the application
        id - the object's id
        Returns:
        true if in cache
        See Also:
        Cache.contains(java.lang.String)
      • put

        public <T> void put​(String appid,
                            String id,
                            T object)
        Description copied from interface: Cache
        Store an object in the cache.
        Specified by:
        put in interface Cache
        Type Parameters:
        T - the type of object to be cached
        Parameters:
        appid - the name of the application
        id - the object's id, not null or empty
        object - the object itself, not null
        See Also:
        Cache.put(java.lang.String, java.lang.Object)
      • put

        public <T> void put​(String appid,
                            String id,
                            T object,
                            Long ttlSeconds)
        Description copied from interface: Cache
        Store an object in the cache.
        Specified by:
        put in interface Cache
        Type Parameters:
        T - the type of object to be cached
        Parameters:
        appid - the name of the application
        id - the object's id, not null or empty
        object - the object itself, not null
        ttlSeconds - the time to live for an object before it is evicted from the cache.
        See Also:
        Cache.put(java.lang.String, java.lang.Object)
      • putAll

        public <T> void putAll​(String appid,
                               Map<String,​T> objects)
        Description copied from interface: Cache
        Store all objects in cache, except those which are null.
        Specified by:
        putAll in interface Cache
        Type Parameters:
        T - any object, not null
        Parameters:
        appid - the name of the application
        objects - map of id - object
        See Also:
        Cache.putAll(java.util.Map)
      • get

        public <T> T get​(String appid,
                         String id)
        Description copied from interface: Cache
        Read an object from cache.
        Specified by:
        get in interface Cache
        Type Parameters:
        T - the type of object to be cached
        Parameters:
        appid - the name of the application
        id - the object's id, not null or empty
        Returns:
        the object from cache or null if not found
        See Also:
        Cache.get(java.lang.String)
      • getAll

        public <T> Map<String,​T> getAll​(String appid,
                                              List<String> ids)
        Description copied from interface: Cache
        Read a number of objects given a list of their ids.
        Specified by:
        getAll in interface Cache
        Type Parameters:
        T - the type of object to be cached
        Parameters:
        appid - the name of the application
        ids - the ids, not null or empty
        Returns:
        a map of the objects that are contained in cache (may be empty)
        See Also:
        Cache.getAll(java.util.List)
      • remove

        public void remove​(String appid,
                           String id)
        Description copied from interface: Cache
        Remove an object from cache.
        Specified by:
        remove in interface Cache
        Parameters:
        appid - the name of the application
        id - the object's id, not null or empty
        See Also:
        Cache.remove(java.lang.String)
      • removeAll

        public void removeAll​(String appid)
        Description copied from interface: Cache
        Clears the cache.
        Specified by:
        removeAll in interface Cache
        Parameters:
        appid - the name of the application
        See Also:
        Cache.removeAll()
      • removeAll

        public void removeAll​(String appid,
                              List<String> ids)
        Description copied from interface: Cache
        Remove a number of objects from cache given a list of their ids.
        Specified by:
        removeAll in interface Cache
        Parameters:
        appid - the name of the application
        ids - the ids, not null or empty
        See Also:
        Cache.removeAll(java.util.List)
      • contains

        public boolean contains​(String id)
        Description copied from interface: Cache
        Do we have this object in the cache?
        Specified by:
        contains in interface Cache
        Parameters:
        id - the object's id
        Returns:
        true if in cache
      • put

        public <T> void put​(String id,
                            T object)
        Description copied from interface: Cache
        Store an object in the cache.
        Specified by:
        put in interface Cache
        Type Parameters:
        T - the type of object to be cached
        Parameters:
        id - the object's id, not null or empty
        object - the object itself, not null
      • putAll

        public <T> void putAll​(Map<String,​T> objects)
        Description copied from interface: Cache
        Store all objects in cache, except those which are null.
        Specified by:
        putAll in interface Cache
        Type Parameters:
        T - any object, not null
        Parameters:
        objects - map of id - object
      • get

        public <T> T get​(String id)
        Description copied from interface: Cache
        Read an object from cache.
        Specified by:
        get in interface Cache
        Type Parameters:
        T - the type of object to be cached
        Parameters:
        id - the object's id, not null or empty
        Returns:
        the object from cache or null if not found
      • getAll

        public <T> Map<String,​T> getAll​(List<String> ids)
        Description copied from interface: Cache
        Read a number of objects given a list of their ids.
        Specified by:
        getAll in interface Cache
        Type Parameters:
        T - the type of object to be cached
        Parameters:
        ids - the ids, not null or empty
        Returns:
        a map of the objects that are contained in cache (may be empty)
      • remove

        public void remove​(String id)
        Description copied from interface: Cache
        Remove an object from cache.
        Specified by:
        remove in interface Cache
        Parameters:
        id - the object's id, not null or empty
      • removeAll

        public void removeAll()
        Description copied from interface: Cache
        Clears the cache.
        Specified by:
        removeAll in interface Cache
      • removeAll

        public void removeAll​(List<String> ids)
        Description copied from interface: Cache
        Remove a number of objects from cache given a list of their ids.
        Specified by:
        removeAll in interface Cache
        Parameters:
        ids - the ids, not null or empty