<p>你似乎没有仔细阅读<a href="http://pythonhosted.org/Flask-Cache/" rel="nofollow">Flask-Cache documentation</a>。缓存不会忽略参数,并且缓存键是可自定义的。项目提供的装饰器已经为您提供了所需的功能。在</p>
<p>从<a href="http://pythonhosted.org/Flask-Cache/#caching-view-functions" rel="nofollow"><em>Caching View Functions</em> section</a>:</p>
<blockquote>
<p>This decorator will use <code>request.path</code> by default for the <code>cache_key</code>.</p>
</blockquote>
<p>因此,<em>默认的</em>缓存键是<code>request.path</code>,但是您可以指定一个不同的键。{eem></em>使函数</em>成为默认的参数。在</p>
<p>从<a href="http://pythonhosted.org/Flask-Cache/#flask.ext.cache.Cache.cached" rel="nofollow">^{<cd3>} decorator documentation</a>:</p>
<blockquote>
<p><code>cached(timeout=None, key_prefix='view/%s', unless=None)</code></p>
<p>By default the cache key is <em>view/request.path</em>. You are able to use this decorator with any function by changing the <em>key_prefix</em>. If the token <em>%s</em> is located within the <em>key_prefix</em> then it will replace that with <em>request.path</em>. You are able to use this decorator with any function by changing the <em>key_prefix</em>.</p>
</blockquote>
<p>以及</p>
<blockquote>
<p><code>key_prefix</code> – <em>[...]</em> Can optionally be a callable which takes no arguments but returns a string that will be used as the <code>cache_key</code>.</p>
</blockquote>
<p>因此,您可以将<code>key_prefix</code>设置为一个函数,它将被调用(不带参数)以生成密钥。在</p>
<p>此外:</p>
<blockquote>
<p>The returned decorated function now has three function attributes assigned to it. These attributes are readable/writable:</p>
<p><em>[...]</em></p>
<p><code>make_cache_key</code><br/>
A function used in generating the cache_key used.</p>
</blockquote>
<p>传递此函数的参数与传递视图函数的参数相同。总之,这允许您生成所需的任何缓存键;要么使用<code>key_prefix</code>并从<code>request</code>或{<cd7>}或其他源中提取更多信息,要么分配给<code>view_function.make_cache_key</code>并访问view函数接收的相同参数。在</p>
<p>然后是<a href="http://pythonhosted.org/Flask-Cache/#flask.ext.cache.Cache.memoize" rel="nofollow">^{<cd9>} decorator</a>:</p>
<blockquote>
<p><code>memoize(timeout=None, make_name=None, unless=None)</code></p>
<p>Use this to cache the result of a function, taking its arguments into account in the cache key.</p>
</blockquote>
<p>所以这个修饰符完全基于传递给函数的参数来缓存返回值。它也支持<code>make_cache_key</code>函数。在</p>
<p>我使用了这两个decorator使googleappengineflask项目的规模达到每月两位数的数百万次浏览量,并将结果存储在googlememcached结构中。使用Redis只需要设置一个配置选项。在</p>