Interface CachedDataManager.Container<T extends CachedData>

Type Parameters:
T - the data type
Enclosing interface:
CachedDataManager

public static interface CachedDataManager.Container<T extends CachedData>
Manages a specific type of cached data within a CachedDataManager instance.
  • Method Details

    • get

      @NonNull T get(@NonNull QueryOptions queryOptions)
      Gets data from the cache.
      Parameters:
      queryOptions - the query options
      Returns:
      a data instance
      Throws:
      NullPointerException - if contexts is null
    • calculate

      @NonNull T calculate(@NonNull QueryOptions queryOptions)
      Calculates data, bypassing the cache.

      The result of this operation is calculated each time the method is called. The result is not added to the internal cache.

      It is therefore highly recommended to use get(QueryOptions) instead.

      The use cases of this method are more around constructing one-time instances of data, without adding the result to the cache.

      Parameters:
      queryOptions - the query options
      Returns:
      a data instance
      Throws:
      NullPointerException - if contexts is null
    • recalculate

      void recalculate(@NonNull QueryOptions queryOptions)
      (Re)calculates data for a given context.

      This method returns immediately in all cases. The (re)calculation is performed asynchronously and applied to the cache in the background.

      If there was a previous data instance associated with the given QueryOptions, then that instance will continue to be returned by get(QueryOptions) until the recalculation is completed.

      If there was no value calculated and cached prior to the call of this method, then one will be calculated.

      Parameters:
      queryOptions - the query options
      Throws:
      NullPointerException - if contexts is null
    • reload

      @NonNull CompletableFuture<? extends T> reload(@NonNull QueryOptions queryOptions)
      (Re)loads permission data for a given context.

      Unlike recalculate(QueryOptions), this method immediately invalidates any previous data values contained within the cache, and then schedules a task to reload a new data instance to replace the one which was invalidated.

      The invalidation happens immediately during the execution of this method. The result of the re-computation encapsulated by the future.

      Subsequent calls to get(QueryOptions) will block until the result of this operation is complete.

      If there was no value calculated and cached prior to the call of this method, then one will be calculated.

      This method returns a Future so users can optionally choose to wait until the recalculation has been performed.

      Parameters:
      queryOptions - the query options.
      Returns:
      a future
      Throws:
      NullPointerException - if contexts is null
    • recalculate

      void recalculate()
      Recalculates data for all known contexts.

      This method returns immediately. The recalculation is performed asynchronously and applied to the cache in the background.

      The previous data instances will continue to be returned by get(QueryOptions) until the recalculation is completed.

    • reload

      Reloads permission data for all known contexts.

      Unlike recalculate(), this method immediately invalidates all previous data values contained within the cache, and then schedules a task to reload new data instances to replace the ones which were invalidated.

      The invalidation happens immediately during the execution of this method. The result of the re-computation encapsulated by the future.

      Subsequent calls to get(QueryOptions) will block until the result of this operation is complete.

      This method returns a Future so users can optionally choose to wait until the recalculation has been performed.

      Returns:
      a future
    • invalidate

      void invalidate(@NonNull QueryOptions queryOptions)
      Invalidates any cached data instances mapped to the given context.
      Parameters:
      queryOptions - the queryOptions to invalidate for
    • invalidate

      void invalidate()
      Invalidates all cached data instances.