Class CachingSupplier<V>

java.lang.Object
io.github.douira.glsl_transformer.core.CachingSupplier<V>
All Implemented Interfaces:
Supplier<V>

public class CachingSupplier<V> extends Object implements Supplier<V>
Wraps a supplier and caches its result according to a given cache policy.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    CachingSupplier(CachePolicy cachePolicy, Supplier<V> generator)
    Creates a new caching supplier with a given cache policy and supplier.
  • Method Summary

    Modifier and Type
    Method
    Description
    get()
     
    void
    invalidate(CachePolicy fulfilledPolicy)
    Invalidates the cached value if the cache policy of this caching supplier requires it based on the strength of the given cache invalidation event.
    static <V> Supplier<V>
    of(CachePolicy cachePolicy, Supplier<V> generator)
    Returns any supplier that supplies the same values as a caching supplier with the given cache policy and value generating supplier.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CachingSupplier

      protected CachingSupplier(CachePolicy cachePolicy, Supplier<V> generator)
      Creates a new caching supplier with a given cache policy and supplier.
      Parameters:
      cachePolicy - The cache policy
      generator - The supplier
  • Method Details

    • get

      public V get()
      Specified by:
      get in interface Supplier<V>
    • invalidate

      public void invalidate(CachePolicy fulfilledPolicy)
      Invalidates the cached value if the cache policy of this caching supplier requires it based on the strength of the given cache invalidation event.
      Parameters:
      fulfilledPolicy - The strength of the cache invalidation event
    • of

      public static <V> Supplier<V> of(CachePolicy cachePolicy, Supplier<V> generator)
      Returns any supplier that supplies the same values as a caching supplier with the given cache policy and value generating supplier. This means that if the CachePolicy#ALWAYS is used, the returned supplier will be the same as the given supplier.
      Type Parameters:
      V - The value type
      Parameters:
      cachePolicy - The cache policy to use on the returned supplier
      generator - The supplier to use on the returned supplier
      Returns:
      A supplier with the given cache policy