Class Cache<E>

  • Type Parameters:
    E -

    abstract class Cache<E>
    extends java.lang.Object
    Abstract cache that automatically removes entries for a hostname once the TTL for an entry is reached.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private class  Cache.Entries  
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.util.concurrent.ScheduledFuture<?> CANCELLED  
      private static java.util.concurrent.atomic.AtomicReferenceFieldUpdater<Cache.Entries,​java.util.concurrent.ScheduledFuture> FUTURE_UPDATER  
      (package private) static int MAX_SUPPORTED_TTL_SECS  
      private java.util.concurrent.ConcurrentMap<java.lang.String,​Cache.Entries> resolveCache  
    • Constructor Summary

      Constructors 
      Constructor Description
      Cache()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) void cache​(java.lang.String hostname, E value, int ttl, EventLoop loop)
      Cache a value for the given hostname that will automatically expire once the TTL is reached.
      (package private) void clear()
      Remove everything from the cache.
      (package private) boolean clear​(java.lang.String hostname)
      Clear all entries (if anything exists) for the given hostname and return true if anything was removed.
      protected abstract boolean equals​(E entry, E otherEntry)
      Returns true if both entries are equal.
      (package private) java.util.List<? extends E> get​(java.lang.String hostname)
      Returns all caches entries for the given hostname.
      protected abstract boolean shouldReplaceAll​(E entry)
      Returns true if this entry should replace all other entries that are already cached for the hostname.
      (package private) int size()
      Return the number of hostnames for which we have cached something.
      protected void sortEntries​(java.lang.String hostname, java.util.List<E> entries)
      Sort the List for a hostname before caching these.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • FUTURE_UPDATER

        private static final java.util.concurrent.atomic.AtomicReferenceFieldUpdater<Cache.Entries,​java.util.concurrent.ScheduledFuture> FUTURE_UPDATER
      • CANCELLED

        private static final java.util.concurrent.ScheduledFuture<?> CANCELLED
      • MAX_SUPPORTED_TTL_SECS

        static final int MAX_SUPPORTED_TTL_SECS
      • resolveCache

        private final java.util.concurrent.ConcurrentMap<java.lang.String,​Cache.Entries> resolveCache
    • Constructor Detail

      • Cache

        Cache()
    • Method Detail

      • clear

        final void clear()
        Remove everything from the cache.
      • clear

        final boolean clear​(java.lang.String hostname)
        Clear all entries (if anything exists) for the given hostname and return true if anything was removed.
      • get

        final java.util.List<? extends E> get​(java.lang.String hostname)
        Returns all caches entries for the given hostname.
      • cache

        final void cache​(java.lang.String hostname,
                         E value,
                         int ttl,
                         EventLoop loop)
        Cache a value for the given hostname that will automatically expire once the TTL is reached.
      • size

        final int size()
        Return the number of hostnames for which we have cached something.
      • shouldReplaceAll

        protected abstract boolean shouldReplaceAll​(E entry)
        Returns true if this entry should replace all other entries that are already cached for the hostname.
      • sortEntries

        protected void sortEntries​(java.lang.String hostname,
                                   java.util.List<E> entries)
        Sort the List for a hostname before caching these.
      • equals

        protected abstract boolean equals​(E entry,
                                          E otherEntry)
        Returns true if both entries are equal.