Migrated issue, originally created by lxyu (lxyu)
I need a feature to get/create multi in one call.
Take this code for example
#!python
def get_order(order_id):
return DBSession().query(Order).get(order_id)
def mget_order(order_ids):
orders = DBSession().query(Order).filter(Order.id.in_(order_ids))
return {order.id: order for order in orders}
The cache_on_arguments works great for the fist get_order function. But for the later one, if I mget [1, 2, 3] and [1, 2], they'll generate 2 cached value, and if a single element in the ids expired, the whole cache expired.
So I want to let the later one make use of the first function's cache. Then mget [1, 2, 3, 4, 5] will directly make use of cache generated in 'get', and if say [2, 3] expired, we only need to regenerate [2, 3]. It'll be much more fast and efficient when ids list grow larger.
While I go through the source code, the cache_on_arguments use a Lock from dogpile.core with this code, which seems not very suitable to do the multiple way in my situation.
#!python
with Lock(
self._mutex(key),
gen_value,
get_value,
expiration_time,
async_creator) as value:
return value
So do you have any suggestions on how to accomplish this goal?
Attachments: 33.patch
Migrated issue, originally created by lxyu (lxyu)
I need a feature to get/create multi in one call.
Take this code for example
The
cache_on_argumentsworks great for the fistget_orderfunction. But for the later one, if I mget[1, 2, 3]and[1, 2], they'll generate 2 cached value, and if a single element in the ids expired, the whole cache expired.So I want to let the later one make use of the first function's cache. Then mget
[1, 2, 3, 4, 5]will directly make use of cache generated in 'get', and if say[2, 3]expired, we only need to regenerate[2, 3]. It'll be much more fast and efficient when ids list grow larger.While I go through the source code, the
cache_on_argumentsuse aLockfromdogpile.corewith this code, which seems not very suitable to do the multiple way in my situation.So do you have any suggestions on how to accomplish this goal?
Attachments: 33.patch