CacheManager class

The cache manager provides simple key-value storage at a high-speed data storage layer (Redis) speeding up data set and get operations.

The values stored can be a single JSON object, an array of objects or primitive values (e.g., numbers, text, boolean). Values can be stored with an optional time-to-live (TTL) to automatically expire entries.

You can directly store primitive values such as integers, strings, etc., however, when you try to get them Altogic returns them wrapped in a simple object with a key named value. As an example if you store a text field "Hello world!" at a key named 'welcome', when you try to get the value of this key using the get method, you will receive the following response: { value: "Hello world"}.

Inheritance

Constructors

CacheManager(Fetcher fetcher)
Creates an instance of CacheManager to make caching requests to your backend app. @param {Fetcher} fetcher The http client to make RESTful API calls to the application's execution engine

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

decrement(String key, {int decrement = 1, int? ttl}) Future<APIResponse<Map<String, dynamic>>>
Decrements the value of the number stored at the key by the decrement amount. If decrement amount not specified, decrements the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation. If ttl specified, sets the stored entry to automatically expire in specified seconds. Any previous time to live associated with the key is discarded on successful decrement operation.
delete(dynamic keys) Future<APIError?>
Removes the specified key(s) from the cache. Irrespective of whether the key is found or not, success response is returned.
expire(String key, int ttl) Future<APIError?>
Sets a timeout on key. After the timeout has expired, the key will automatically be deleted.
get(String key) Future<APIResponse<Map<String, dynamic>>>
Gets an item from the cache by key. If key is not found, then null is returned as data.
getStats() Future<APIResponse<Map<String, dynamic>>>
Returns the overall information about your apps cache including total number of keys and total storage size (bytes), daily and monthly ingress and egress volumes (bytes).
increment(String key, {int increment = 1, int? ttl}) Future<APIResponse<Map<String, dynamic>>>
Increments the value of the number stored at the key by the increment amount. If increment amount not specified, increments the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation. If ttl specified, sets the stored entry to automatically expire in specified seconds. Any previous time to live associated with the key is discarded on successful increment operation.
listKeys({String? pattern, String? next}) Future<KeyListResult>
Gets the list of keys in your app cache storage. If pattern is specified, it runs the pattern match to narrow down returned results, otherwise, returns all keys contained in your app's cache storage. See below examples how to specify filtering pattern:
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
set(String key, Object value, [int? ttl]) Future<APIError?>
Sets an item in the cache. Overwrites any existing value already set. If ttl specified, sets the stored entry to automatically expire in specified seconds. Any previous time to live associated with the key is discarded on successful set operation.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited