Class AlpineStore<K,D>
- Type Parameters:
K
- the key typeD
- the data type
- All Implemented Interfaces:
Activatable
AlpineDriver
.
Inheritors should never be manually instantiated.
- Since:
- 0.1.0
-
Field Summary
Modifier and TypeFieldDescriptionprotected final AlpinePlugin
The plugin that activated this store -
Constructor Summary
ModifierConstructorDescriptionprotected
AlpineStore
(AlpinePlugin plugin, AlpineDriver<K, D> driver) Simple constructor using the default caching strategy.protected
AlpineStore
(AlpinePlugin plugin, AlpineDriver<K, D> driver, CachingStrategy strategy) Constructor that allows the configuration of a caching strategy. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
activate
(@NotNull AlpinePlugin context) Activate this object.final void
deactivate
(@NotNull AlpinePlugin context) Deactivate this object.boolean
flush()
Persists cached data entries to the underlying data storage.boolean
Persists a cached data entry associated with the given key to the underlying data storage.final D
Get data stored at a given key.final D
getOrCreate
(K key, @NotNull Supplier<D> defaultDataSupplier) Get data stored at a given key, or create an entry if there is none.final D
getOrCreate
(K key, D defaultData) Get data stored at a given key, or create an entry if there is none.final boolean
Check if data exists for a given key.final boolean
isActive()
Is this object active?final @NotNull Collection<D>
Retrieve all stored data entries from the underlying data storage.final @NotNull Collection<D>
loadAllEntries
(@Nullable Consumer<Exception> exceptionHandler) Retrieve all stored data entries from the underlying data storage.final void
Store data at a given key.final boolean
Delete data stored at a given key.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface co.crystaldev.alpinecore.framework.Activatable
canDeactivate
-
Field Details
-
plugin
The plugin that activated this store
-
-
Constructor Details
-
AlpineStore
Simple constructor using the default caching strategy.Locked down to prevent improper instantiation.
Stores are reflectively instantiated by the framework automatically.
- Parameters:
driver
- the storage driver- Since:
- 0.1.0
-
AlpineStore
Constructor that allows the configuration of a caching strategy.Locked down to prevent improper instantiation.
Stores are reflectively instantiated by the framework automatically.
- Parameters:
driver
- the storage driverstrategy
- the strategy used by the caching layer- Since:
- 0.1.0
-
-
Method Details
-
get
Get data stored at a given key.- Parameters:
key
- the key- Returns:
- the data
-
getOrCreate
Get data stored at a given key, or create an entry if there is none.- Parameters:
key
- the keydefaultData
- the data to create a new entry with- Returns:
- the data
-
getOrCreate
@NotNull public final D getOrCreate(@NotNull K key, @NotNull @NotNull Supplier<D> defaultDataSupplier) Get data stored at a given key, or create an entry if there is none.- Parameters:
key
- the keydefaultDataSupplier
- the data to create a new entry with- Returns:
- the data
-
loadAllEntries
Retrieve all stored data entries from the underlying data storage.It may be a blocking task, and the time it takes to complete depends on the size of the data storage.
- Returns:
- A collection containing all stored data entries.
- Throws:
Exception
- If an exception occurs while retrieving the data entries.- See Also:
-
loadAllEntries
@NotNull public final @NotNull Collection<D> loadAllEntries(@Nullable @Nullable Consumer<Exception> exceptionHandler) Retrieve all stored data entries from the underlying data storage.It may be a blocking task, and the time it takes to complete depends on the size of the data storage.
- Parameters:
exceptionHandler
- A function for handling errors.- Returns:
- A collection containing all stored data entries.
- See Also:
-
has
Check if data exists for a given key.- Parameters:
key
- the key- Returns:
- whether an entry exists
-
remove
Delete data stored at a given key.- Parameters:
key
- the key- Returns:
- whether the operation was successful
-
put
Store data at a given key.This method will silently overwrite any pre-existing data.
- Parameters:
key
- the keydata
- the data
-
flush
public boolean flush()Persists cached data entries to the underlying data storage.This method is responsible for persisting data entries that have been cached but not yet saved to the underlying data storage. It attempts to persist the entries and clears the cache.
- Returns:
- whether the operation was successful
-
flush
Persists a cached data entry associated with the given key to the underlying data storage.This method is responsible for persisting a specific data entry that has been cached but not yet saved to the underlying data storage. It attempts to persist the entry and returns whether the operation was successful. If the persistence operation fails, it logs an error message.
- Parameters:
key
- The key associated with the data entry to be persisted.- Returns:
- Whether the persistence operation was successful.
-
activate
Description copied from interface:Activatable
Activate this object.- Specified by:
activate
in interfaceActivatable
- Parameters:
context
- The plugin which initiated the request
-
deactivate
Description copied from interface:Activatable
Deactivate this object.- Specified by:
deactivate
in interfaceActivatable
- Parameters:
context
- The plugin which initiated the request
-
isActive
public final boolean isActive()Description copied from interface:Activatable
Is this object active?- Specified by:
isActive
in interfaceActivatable
- Returns:
- Whether the object is active
-