CachedPrfObject<T> class
abstract
A preference object that caches values in memory for faster access.
This extends BasePrfObject by maintaining an in-memory cache of the most recent value, reducing disk reads when the same value is accessed multiple times. This improves performance but is not recommended for use in isolates since the cache is not shared between isolates.
- Inheritance
-
- Object
- BasePrfObject<
T> - CachedPrfObject
- Implementers
- Available extensions
Constructors
- CachedPrfObject.new(String key, {T? defaultValue})
-
Creates a new cached preference object with the given
key
and optionaldefaultValue
.
Properties
-
adapter
→ PrfAdapter<
T> -
The adapter used to convert between the type
T
and SharedPreferences.no setterinherited - cachedValue → T?
-
Returns the currently cached value without accessing SharedPreferences.
no setter
- defaultValue → T?
-
Optional default value to use when no value exists for key.
finalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → String
-
The key used to store this preference in SharedPreferences.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
existsOnPrefs(
) → Future< bool> -
Available on BasePrfObject<
Checks if the key exists in the default PrfService instance.T> , provided by the PrfOperationExtensions extension -
get(
) → Future< T?> -
Available on BasePrfObject<
Gets the value from the default PrfService instance.T> , provided by the PrfOperationExtensions extension -
getOrFallback(
T fallback) → Future< T> -
Available on BasePrfObject<
Gets the value or returns the provided fallback if the value is null.T> , provided by the PrfOperationExtensions extension -
getValue(
SharedPreferencesAsync prefs) → Future< T?> -
Gets the value, using the cached value if available or reading from storage if not.
override
-
initCache(
SharedPreferencesAsync prefs) → Future< void> - Initializes the cache by reading the current value from SharedPreferences.
-
isNull(
) → Future< bool> -
Available on BasePrfObject<
Checks if the value is null in the default PrfService instance.T> , provided by the PrfOperationExtensions extension -
isValueNull(
SharedPreferencesAsync prefs) → Future< bool> -
Checks if the stored value is null.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
remove(
) → Future< void> -
Available on BasePrfObject<
Removes the value from the default PrfService instance.T> , provided by the PrfOperationExtensions extension -
removeValue(
SharedPreferencesAsync prefs) → Future< void> -
Removes the value from SharedPreferences and clears the cached value.
override
-
set(
T value) → Future< void> -
Available on BasePrfObject<
Sets the value using the default PrfService instance.T> , provided by the PrfOperationExtensions extension -
setValue(
SharedPreferencesAsync prefs, T value) → Future< void> -
Stores
value
in SharedPreferences and updates the cached value.override -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited