Class CachedStorageProvider<K,V>

java.lang.Object
dev.crafty.core.storage.providers.CachedStorageProvider<K,V>
All Implemented Interfaces:
StorageProvider<K,V>

public class CachedStorageProvider<K,V> extends Object implements StorageProvider<K,V>
  • Constructor Details

    • CachedStorageProvider

      public CachedStorageProvider(StorageProvider<K,V> delegate)
    • CachedStorageProvider

      public CachedStorageProvider(StorageProvider<K,V> delegate, com.github.benmanes.caffeine.cache.Caffeine<Object,Object> cacheBuilder, com.github.benmanes.caffeine.cache.Caffeine<Object,Object> collectionCacheBuilder)
  • Method Details

    • save

      public CompletableFuture<Void> save(K key, V value)
      Description copied from interface: StorageProvider
      Saves an object to the storage.
      Specified by:
      save in interface StorageProvider<K,V>
      Parameters:
      key - The key to identify the object
      value - The object to save
      Returns:
      A CompletableFuture that completes when the operation is done
    • get

      public CompletableFuture<Optional<V>> get(K key)
      Description copied from interface: StorageProvider
      Retrieves an object from the storage.
      Specified by:
      get in interface StorageProvider<K,V>
      Parameters:
      key - The key of the object to retrieve
      Returns:
      A CompletableFuture that completes with the retrieved object, or empty if not found
    • getAll

      public CompletableFuture<Collection<V>> getAll()
      Description copied from interface: StorageProvider
      Retrieves all objects from the storage.
      Specified by:
      getAll in interface StorageProvider<K,V>
      Returns:
      A CompletableFuture that completes with a collection of all objects
    • delete

      public CompletableFuture<Void> delete(K key)
      Description copied from interface: StorageProvider
      Deletes an object from the storage.
      Specified by:
      delete in interface StorageProvider<K,V>
      Parameters:
      key - The key of the object to delete
      Returns:
      A CompletableFuture that completes when the operation is done
    • exists

      public CompletableFuture<Boolean> exists(K key)
      Description copied from interface: StorageProvider
      Checks if an object exists in the storage.
      Specified by:
      exists in interface StorageProvider<K,V>
      Parameters:
      key - The key to check
      Returns:
      A CompletableFuture that completes with true if the object exists, false otherwise
    • initialize

      public CompletableFuture<Void> initialize()
      Description copied from interface: StorageProvider
      Initializes the storage provider. This method should be called before using the provider.
      Specified by:
      initialize in interface StorageProvider<K,V>
      Returns:
      A CompletableFuture that completes when initialization is done
    • close

      public CompletableFuture<Void> close()
      Description copied from interface: StorageProvider
      Closes the storage provider and releases any resources. This method should be called when the provider is no longer needed.
      Specified by:
      close in interface StorageProvider<K,V>
      Returns:
      A CompletableFuture that completes when the provider is closed