Class RedisCache<T>

  • Type Parameters:
    T - the type to cache.
    All Implemented Interfaces:
    Cache<T>

    public class RedisCache<T>
    extends Object
    implements Cache<T>
    Redis Cache implementation.
    Author:
    Richard Kohlen
    • Constructor Detail

      • RedisCache

        public RedisCache​(org.springframework.data.redis.core.RedisTemplate<String,​T> redisTemplate,
                          HawaiiTime hawaiiTime,
                          Long defaultExpireInMinutes,
                          String keyPrefix)
        Constructor.
        Parameters:
        redisTemplate - The redis template to use.
        hawaiiTime - the Hawaii time, used to get the current time.
        defaultExpireInMinutes - The default time out in minutes.
        keyPrefix - They key's prefix.
    • Method Detail

      • put

        public void put​(@NotNull
                        @NotNull String key,
                        @NotNull
                        T value)
        Put the object in the cache with the given key.

        The object is stored for the default configured time, depending on the cache implementation. See general remarks about cache evictions.

        Specified by:
        put in interface Cache<T>
        Parameters:
        key - The (not null) key to store the object under.
        value - The (not null) object to store.
      • put

        public void put​(@NotNull
                        @NotNull String key,
                        @NotNull
                        T value,
                        @NotNull
                        @NotNull Duration duration)
        Put the object in the cache with the given key for the given duration.

        The object is stored for the requested duration. See general remarks about cache evictions.

        Specified by:
        put in interface Cache<T>
        Parameters:
        key - The (not null) key to store the object under.
        value - The (not null) object to store.
        duration - The (not null) duration to store the object for.
      • put

        public void put​(@NotNull
                        @NotNull String key,
                        @NotNull
                        T value,
                        @NotNull
                        @NotNull LocalDateTime expiresAt)
        Put the object in the cache with the given key for until expiresAt has come.

        The object is stored and should be removed when expiresAt had come.

        Specified by:
        put in interface Cache<T>
        Parameters:
        key - The (not null) key to store the object under.
        value - The (not null) object to store.
        expiresAt - The (not null) expiry time.
      • put

        public void put​(@NotNull
                        @NotNull String key,
                        @NotNull
                        T value,
                        @NotNull
                        @NotNull ZonedDateTime expiresAt)
        Put the object in the cache with the given key for until expiresAt has come.

        The object is stored and should be removed when expiresAt had come.

        Specified by:
        put in interface Cache<T>
        Parameters:
        key - The (not null) key to store the object under.
        value - The (not null) object to store.
        expiresAt - The (not null) expiry time.
      • get

        public T get​(@NotNull
                     @NotNull String key)
        Retrieve the object stored under the key.
        Specified by:
        get in interface Cache<T>
        Parameters:
        key - The (never null) key to retrieve the value with.
        Returns:
        The value, or null if the object is not found.
      • remove

        public void remove​(@NotNull
                           @NotNull String key)
        Remove the value associate with the key.
        Specified by:
        remove in interface Cache<T>
        Parameters:
        key - The key to remove.