class Clear::Model::QueryCache
- Clear::Model::QueryCache
- Reference
- Object
Overview
The Clear::Model::QueryCache is a fire-and-forget cache used when caching associations and preventing N+1 queries anti-pattern.
This is not a global cache: One cache instance exists per collection, and the cache disappear at the same time the Collection is unreferenced.
Each cache can references multiples relations at the same time. This cache use an underlying hash to access to the references keys.
Defined in:
clear/model/query_cache.crInstance Method Summary
-
#active(relation_name)
Tell this cache than we active the cache over a specific relation name.
-
#active?(relation_name)
Check whether the cache is active on a certain association.
-
#clear
Empty the cache and flag all relations has unactive
- #fetch
-
#hit(relation_name, relation_value, klass : T.class) : Array(T) forall T
Try to hit the cache.
-
#set(relation_name, relation_value, arr : Array(T)) forall T
Set the cached array for a specific key
{relation_name,relation_value}
-
#with_cache(&)
Perform some operations with the cache then eventually clear the cache.
Instance Method Detail
Tell this cache than we active the cache over a specific relation name.
Returns self
Check whether the cache is active on a certain association.
Returns true
if relation_name
is flagged as encached, or false
otherwise.
Try to hit the cache. If an array is found, it will be returned. Otherwise, empty array is returned.
This methods do not check if a relation flagged as is actively cached or not. Therefore, hitting a non-cached relation will return always an empty-array.
Set the cached array for a specific key {relation_name,relation_value}