Class BOCache<T>

java.lang.Object
overit.geocallapp.utilities.core.cache.BOCache<T>
Type Parameters:
T - the type of business objects stored in this cache
All Implemented Interfaces:
Serializable

public class BOCache<T> extends Object implements Serializable
Generic cache implementation for business objects with lazy loading capabilities.
This class provides a thread-safe caching mechanism for business objects that are loaded on-demand using LoadEvent instances. The cache automatically loads objects when they are first requested and stores them for subsequent access.
Key features:
  • Thread-safe operations using synchronized methods
  • Lazy loading of objects using configurable LoadEvent classes
  • Automatic PoolKit management for database operations
  • Factory-based instantiation for dependency injection support
  • Error handling with logging for failed load operations
Since:
1.0
See Also:
GCApi:
bo
  • Field Details

  • Constructor Details

    • BOCache

      public BOCache()
  • Method Details

    • makeBOCache

      public static <T> BOCache<T> makeBOCache(Class<? extends LoadEvent<T>> loadEventClass)
      Factory method to create a new cache instance with the specified LoadEvent class.
      Type Parameters:
      T - the type of objects to be cached
      Parameters:
      loadEventClass - the LoadEvent class used to load objects into the cache
      Returns:
      a new cache instance configured with the specified LoadEvent class
    • makeBOCache

      public static <T> BOCache<T> makeBOCache(Class<? extends LoadEvent<T>> loadEventClass, EventOptions eventOptions)
      Factory method to create a new cache instance with the specified LoadEvent class.
      Type Parameters:
      T - the type of objects to be cached
      Parameters:
      loadEventClass - the LoadEvent class used to load objects into the cache
      eventOptions - the EventOptions to configure the event behavior
      Returns:
      a new cache instance configured with the specified LoadEvent class
    • setLoadEventClass

      protected void setLoadEventClass(Class<? extends LoadEvent<T>> loadEventClass)
      Sets the LoadEvent class used for loading objects into the cache.
      Parameters:
      loadEventClass - the LoadEvent class to use for object loading
    • setEventOptions

      protected void setEventOptions(EventOptions eventOptions)
    • get

      public T get(Long key, PoolKit poolKit)
      Retrieves an object from the cache, loading it if not present. This method provides thread-safe access to cached objects. If the requested object is not in the cache, it automatically creates a LoadEvent instance using reflection, executes it with the provided PoolKit, and stores the result in the cache.
      Parameters:
      key - the unique identifier for the object to retrieve
      poolKit - the PoolKit for database operations
      Returns:
      the cached or newly loaded object, or null if loading fails
    • get

      public T get(Long key)
      Retrieves an object from the cache with automatic PoolKit management.
      Parameters:
      key - the unique identifier for the object to retrieve
      Returns:
      the cached or newly loaded object, or null if loading fails or database errors occur
    • getValues

      public Collection<T> getValues()
      Returns all cached objects as a collection. This method provides access to all objects currently stored in the cache. The returned collection is a view of the cache values, so modifications to the cache will be reflected in the collection. Note that this method only returns objects that have already been loaded into the cache. It does not trigger loading of any additional objects.
      Returns:
      a collection containing all cached objects