How to clear a cached query?
<p>I'm using the following method to cache the result of a SQL query:</p>

<pre><code>db(my_query).select(cache=(cache.ram, 3600), cacheable=True)
</code></pre>

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

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

<p>How can I achieve this?</p>

<p>The cache key is a bit complicated to replicate (it is the MD5 hash of the database URI plus the SQL generated for the query). As an alternative, since you have <code>cacheable=True</code>, you can call <code>cache.ram</code> directly with your own key:</p>

<pre><code>rows = cache.ram('my_query', lambda: db(my_query).select(cacheable=True), 3600)
</code></pre>

python python-2.7 web2py pydal