Class GeneralCache


  • public class GeneralCache
    extends java.lang.Object
    General cache class. This class will be statically instantiated. It contains all the structures needed to maintain a cache of objects, with both LRU flushing behavior, and timed expiration of objects. This cache is entirely local to a JVM and does NOT have any locking and synchronization semantics cross-JVM. That is handled at a higher level.
    • Constructor Detail

      • GeneralCache

        public GeneralCache()
    • Method Detail

      • lookup

        public java.lang.Object lookup​(java.lang.Object objectDescription)
        Locate an object in the cache, and return it if found.
        Parameters:
        objectDescription - is the object's unique identifier.
        Returns:
        the object if found, or null if not present in the cache.
      • getObjectCreationTime

        public long getObjectCreationTime​(java.lang.Object objectDescription)
        Get the creation time of an object in the cache.
        Parameters:
        objectDescription - is the object's unique identifier.
        Returns:
        the creation time, or -1 if object not found.
      • getObjectInvalidationKeys

        public StringSet getObjectInvalidationKeys​(java.lang.Object objectDescription)
        Get the invalidation keys for an object in the cache.
        Parameters:
        objectDescription - is the object's unique identifier.
        Returns:
        the keys, or null if not found.
      • getObjectExpirationTime

        public long getObjectExpirationTime​(java.lang.Object objectDescription)
        Get the expiration time for an object in the cache.
        Parameters:
        objectDescription - is the object's unique identifier.
        Returns:
        the expiration time (-1L means none).
      • deleteObject

        public void deleteObject​(java.lang.Object objectDescription)
        Delete a record from the cache.
        Parameters:
        objectDescription - is the unique description.
      • setObject

        public void setObject​(java.lang.Object objectDescription,
                              java.lang.Object object,
                              StringSet keys,
                              long timestamp)
        Add a newly created object to the cache. Use ONLY for newly created objects!
        Parameters:
        objectDescription - is the newly created object's unique description.
        object - is the newly created object itself.
        keys - are the invalidation keys for the newly created object.
        timestamp - is the creation timestamp for this object (used for cross-JVM invalidation)
      • setObjectExpiration

        public void setObjectExpiration​(java.lang.Object objectDescription,
                                        long expirationTime)
        Set an object's expiration time.
        Parameters:
        objectDescription - is the object's unique description.
        expirationTime - is the object's new expiration time, in milliseconds since epoch.
      • setObjectClass

        public void setObjectClass​(java.lang.Object objectDescription,
                                   java.lang.String objectClass,
                                   int maxCount)
        Set an object's class and maximum count. This will clean up extra objects in a Least Recently Used fashion until the count is met.
        Parameters:
        objectDescription - is the object's unique description.
        objectClass - is the object's "class", or grouping for the purposes of LRU.
        maxCount - is the maximum number of objects of the class to permit to remain in the cache.
      • invalidateKeys

        public void invalidateKeys​(StringSet keys)
        Invalidate a set of keys. This causes all objects that have any of the specified keys as invalidation keys to be removed from the cache.
        Parameters:
        keys - is the StringSet describing the keys to invalidate.
      • expireRecords

        public void expireRecords​(long expireTime)
        Expire all records that have older expiration times than that passed in.
        Parameters:
        expireTime - is the time to compare against, in milliseconds since epoch.
      • deleteEntry

        protected void deleteEntry​(GeneralCache.ObjectRecord record)
        Delete a record from the cache. NOTE WELL: This method cannot be used if the data associated with the record is currently being processed with an enumeration (for example), since it modifies the structures that the enumeration is based on!
        Parameters:
        record - is the object record.