enableCaching method
Enables caching for the data retrieval operation.
When called, this method configures the current CoffeeRequestGet<T>
instance to utilize cache storage for data retrieval. It is beneficial for
reducing network traffic and speeding up data access by using locally stored,
cached data when available. The method accepts an optional key
parameter,
which serves as a unique identifier for the cache entry.
Returns a CoffeeRequestGet<T> with caching capabilities enabled.
Usage Examples
Basic caching:
var request = CoffeeRequestGet<CoffeeShop>()
.whereIs('isValid', true)
.enableCaching();
Caching with a custom key:
var request = CoffeeRequestGet<CoffeeShop>()
.whereIs('isOpen', true)
.enableCaching(key: 'openCoffeeShops');
Functional approach with caching:
var request = CoffeeRequestGet<CoffeeShop>()
.whereIs((CoffeeShop shop) => shop.isValid, false)
.enableCaching();
Implementation
CoffeeRequestGet<T> enableCaching({ String key = '' }) {
_useCache = true;
_cacheKey = key;
return this;
}