2

I'm using the following method to cache the result of a SQL query:

db(my_query).select(cache=(cache.ram, 3600), cacheable=True)

In some cases I want to clear this cache before it expires, which could be done by using cache.ram.clear(key) but I actually don't know the key generated by the DAL in the previous code.

I understand cache=(cache.ram, 0) will clear the cache too, but I also have the overhead of executing the query.

How can I achieve this?

4

1 回答 1

2

缓存键的复制有点复杂(它是数据库 URI 的 MD5 哈希加上为查询生成的 SQL)。作为替代方案,既然你有cacheable=True,你可以cache.ram直接用你自己的密钥调用:

rows = cache.ram('my_query', lambda: db(my_query).select(cacheable=True), 3600)
于 2016-09-25T17:56:55.863 回答