You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previously in #169 the support for key references on the same was implemented, like "internal references". Despite this could be the common case scenario, there could be situations where you may want to reference a key that is stored in a different and/or external cache. But let's give a possible use case. Assume we have a Redis cache (using the NebulexRedisAdapter), and you want to optimize the calls to Redis as much as possible. Therefore, you would like to store the referenced keys in a local cache and the actual values in Redis. This way, we only hit Redis for accessing the keys with the actual values, and the referenced keys will be resolved locally.
This is an example of the proposed solution:
defmoduleMyApp.UserAccountsdouseNebulex.CachingaliasMyApp.{LocalCache,RedisCache}@decoratecacheable(cache: RedisCache,key: id)defget_user_account(id)do# your logic ...end@decoratecacheable(cache: LocalCache,key: email,references: &cache_ref(RedisCache,&1.id))defget_user_account_by_email(email)do# your logic ...end@decoratecacheable(cache: LocalCache,key: token,references: &cache_ref(RedisCache,&1.id))defget_user_account_by_token(token)do# your logic ...end@decoratecache_evict(cache: RedisCache,key: user.id)defupdate_user_account(user)do# your logic ...endend
The functions get_user_account/1 and update_user_account/2 use RedisCache to store the real value in Redis while get_user_account_by_email/1 and get_user_account_by_token/1 use LocalCache to store the referenced keys. Then, with the option references: &cache_ref(RedisCache, &1.id) we are telling the cacheable decorator the referenced key given by &1.id is located in the cache RedisCache; underneath, the macro cache_ref/2 builds the special return type for the external cache reference.
The text was updated successfully, but these errors were encountered:
Previously in #169 the support for key references on the same was implemented, like "internal references". Despite this could be the common case scenario, there could be situations where you may want to reference a key that is stored in a different and/or external cache. But let's give a possible use case. Assume we have a Redis cache (using the
NebulexRedisAdapter
), and you want to optimize the calls to Redis as much as possible. Therefore, you would like to store the referenced keys in a local cache and the actual values in Redis. This way, we only hit Redis for accessing the keys with the actual values, and the referenced keys will be resolved locally.This is an example of the proposed solution:
The functions
get_user_account/1
andupdate_user_account/2
useRedisCache
to store the real value in Redis whileget_user_account_by_email/1
andget_user_account_by_token/1
useLocalCache
to store the referenced keys. Then, with the optionreferences: &cache_ref(RedisCache, &1.id)
we are telling thecacheable
decorator the referenced key given by&1.id
is located in the cacheRedisCache
; underneath, the macrocache_ref/2
builds the special return type for the external cache reference.The text was updated successfully, but these errors were encountered: