/usr/share/doc/python-werkzeug-doc/html/contrib/cache.html is in python-werkzeug-doc 0.10.4+dfsg1-1ubuntu1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cache — Werkzeug 0.10.4 documentation</title>
<link rel="stylesheet" href="../_static/werkzeug.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '0.10.4',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="top" title="Werkzeug 0.10.4 documentation" href="../index.html" />
<link rel="up" title="Contributed Modules" href="index.html" />
<link rel="next" title="Extra Wrappers" href="wrappers.html" />
<link rel="prev" title="Secure Cookie" href="securecookie.html" />
</head>
<body role="document">
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="wrappers.html" title="Extra Wrappers"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="securecookie.html" title="Secure Cookie"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Werkzeug 0.10.4 documentation</a> »</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Contributed Modules</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="module-werkzeug.contrib.cache">
<span id="cache"></span><h1>Cache<a class="headerlink" href="#module-werkzeug.contrib.cache" title="Permalink to this headline">¶</a></h1>
<p>The main problem with dynamic Web sites is, well, they’re dynamic. Each
time a user requests a page, the webserver executes a lot of code, queries
the database, renders templates until the visitor gets the page he sees.</p>
<p>This is a lot more expensive than just loading a file from the file system
and sending it to the visitor.</p>
<p>For most Web applications, this overhead isn’t a big deal but once it
becomes, you will be glad to have a cache system in place.</p>
<div class="section" id="how-caching-works">
<h2>How Caching Works<a class="headerlink" href="#how-caching-works" title="Permalink to this headline">¶</a></h2>
<p>Caching is pretty simple. Basically you have a cache object lurking around
somewhere that is connected to a remote cache or the file system or
something else. When the request comes in you check if the current page
is already in the cache and if so, you’re returning it from the cache.
Otherwise you generate the page and put it into the cache. (Or a fragment
of the page, you don’t have to cache the full thing)</p>
<p>Here is a simple example of how to cache a sidebar for a template:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">get_sidebar</span><span class="p">(</span><span class="n">user</span><span class="p">):</span>
<span class="n">identifier</span> <span class="o">=</span> <span class="s1">'sidebar_for/user</span><span class="si">%d</span><span class="s1">'</span> <span class="o">%</span> <span class="n">user</span><span class="o">.</span><span class="n">id</span>
<span class="n">value</span> <span class="o">=</span> <span class="n">cache</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">identifier</span><span class="p">)</span>
<span class="k">if</span> <span class="n">value</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
<span class="k">return</span> <span class="n">value</span>
<span class="n">value</span> <span class="o">=</span> <span class="n">generate_sidebar_for</span><span class="p">(</span><span class="n">user</span><span class="o">=</span><span class="n">user</span><span class="p">)</span>
<span class="n">cache</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="n">identifier</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mi">60</span> <span class="o">*</span> <span class="mi">5</span><span class="p">)</span>
<span class="k">return</span> <span class="n">value</span>
</pre></div>
</div>
</div>
<div class="section" id="creating-a-cache-object">
<h2>Creating a Cache Object<a class="headerlink" href="#creating-a-cache-object" title="Permalink to this headline">¶</a></h2>
<p>To create a cache object you just import the cache system of your choice
from the cache module and instantiate it. Then you can start working
with that object:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">werkzeug.contrib.cache</span> <span class="kn">import</span> <span class="n">SimpleCache</span>
<span class="gp">>>> </span><span class="n">c</span> <span class="o">=</span> <span class="n">SimpleCache</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">c</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">"foo"</span><span class="p">,</span> <span class="s2">"value"</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">c</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"foo"</span><span class="p">)</span>
<span class="go">'value'</span>
<span class="gp">>>> </span><span class="n">c</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"missing"</span><span class="p">)</span> <span class="ow">is</span> <span class="bp">None</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Please keep in mind that you have to create the cache and put it somewhere
you have access to it (either as a module global you can import or you just
put it into your WSGI application).</p>
</div>
<div class="section" id="cache-system-api">
<h2>Cache System API<a class="headerlink" href="#cache-system-api" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="werkzeug.contrib.cache.BaseCache">
<em class="property">class </em><code class="descclassname">werkzeug.contrib.cache.</code><code class="descname">BaseCache</code><span class="sig-paren">(</span><em>default_timeout=300</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.contrib.cache.BaseCache" title="Permalink to this definition">¶</a></dt>
<dd><p>Baseclass for the cache systems. All the cache systems implement this
API or a superset of it.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>default_timeout</strong> – the default timeout (in seconds) that is used if no
timeout is specified on <a class="reference internal" href="#werkzeug.contrib.cache.BaseCache.set" title="werkzeug.contrib.cache.BaseCache.set"><code class="xref py py-meth docutils literal"><span class="pre">set()</span></code></a>.</td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="werkzeug.contrib.cache.BaseCache.add">
<code class="descname">add</code><span class="sig-paren">(</span><em>key</em>, <em>value</em>, <em>timeout=None</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.contrib.cache.BaseCache.add" title="Permalink to this definition">¶</a></dt>
<dd><p>Works like <a class="reference internal" href="#werkzeug.contrib.cache.BaseCache.set" title="werkzeug.contrib.cache.BaseCache.set"><code class="xref py py-meth docutils literal"><span class="pre">set()</span></code></a> but does not overwrite the values of already
existing keys.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>key</strong> – the key to set</li>
<li><strong>value</strong> – the value for the key</li>
<li><strong>timeout</strong> – the cache timeout for the key or the default
timeout if not specified.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Same as <a class="reference internal" href="#werkzeug.contrib.cache.BaseCache.set" title="werkzeug.contrib.cache.BaseCache.set"><code class="xref py py-meth docutils literal"><span class="pre">set()</span></code></a>, but also <code class="docutils literal"><span class="pre">False</span></code> for already
existing keys.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">boolean</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="werkzeug.contrib.cache.BaseCache.clear">
<code class="descname">clear</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.contrib.cache.BaseCache.clear" title="Permalink to this definition">¶</a></dt>
<dd><p>Clears the cache. Keep in mind that not all caches support
completely clearing the cache.
:returns: Whether the cache has been cleared.
:rtype: boolean</p>
</dd></dl>
<dl class="method">
<dt id="werkzeug.contrib.cache.BaseCache.dec">
<code class="descname">dec</code><span class="sig-paren">(</span><em>key</em>, <em>delta=1</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.contrib.cache.BaseCache.dec" title="Permalink to this definition">¶</a></dt>
<dd><p>Decrements the value of a key by <cite>delta</cite>. If the key does
not yet exist it is initialized with <cite>-delta</cite>.</p>
<p>For supporting caches this is an atomic operation.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>key</strong> – the key to increment.</li>
<li><strong>delta</strong> – the delta to subtract.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">The new value or <cite>None</cite> for backend errors.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="werkzeug.contrib.cache.BaseCache.delete">
<code class="descname">delete</code><span class="sig-paren">(</span><em>key</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.contrib.cache.BaseCache.delete" title="Permalink to this definition">¶</a></dt>
<dd><p>Delete <cite>key</cite> from the cache.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>key</strong> – the key to delete.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Whether the key existed and has been deleted.</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">boolean</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="werkzeug.contrib.cache.BaseCache.delete_many">
<code class="descname">delete_many</code><span class="sig-paren">(</span><em>*keys</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.contrib.cache.BaseCache.delete_many" title="Permalink to this definition">¶</a></dt>
<dd><p>Deletes multiple keys at once.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>keys</strong> – The function accepts multiple keys as positional
arguments.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Whether all given keys have been deleted.</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">boolean</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="werkzeug.contrib.cache.BaseCache.get">
<code class="descname">get</code><span class="sig-paren">(</span><em>key</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.contrib.cache.BaseCache.get" title="Permalink to this definition">¶</a></dt>
<dd><p>Look up key in the cache and return the value for it.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>key</strong> – the key to be looked up.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The value if it exists and is readable, else <code class="docutils literal"><span class="pre">None</span></code>.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="werkzeug.contrib.cache.BaseCache.get_dict">
<code class="descname">get_dict</code><span class="sig-paren">(</span><em>*keys</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.contrib.cache.BaseCache.get_dict" title="Permalink to this definition">¶</a></dt>
<dd><p>Like <a class="reference internal" href="#werkzeug.contrib.cache.BaseCache.get_many" title="werkzeug.contrib.cache.BaseCache.get_many"><code class="xref py py-meth docutils literal"><span class="pre">get_many()</span></code></a> but return a dict:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">d</span> <span class="o">=</span> <span class="n">cache</span><span class="o">.</span><span class="n">get_dict</span><span class="p">(</span><span class="s2">"foo"</span><span class="p">,</span> <span class="s2">"bar"</span><span class="p">)</span>
<span class="n">foo</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="s2">"foo"</span><span class="p">]</span>
<span class="n">bar</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="s2">"bar"</span><span class="p">]</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>keys</strong> – The function accepts multiple keys as positional
arguments.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="werkzeug.contrib.cache.BaseCache.get_many">
<code class="descname">get_many</code><span class="sig-paren">(</span><em>*keys</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.contrib.cache.BaseCache.get_many" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a list of values for the given keys.
For each key a item in the list is created:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">foo</span><span class="p">,</span> <span class="n">bar</span> <span class="o">=</span> <span class="n">cache</span><span class="o">.</span><span class="n">get_many</span><span class="p">(</span><span class="s2">"foo"</span><span class="p">,</span> <span class="s2">"bar"</span><span class="p">)</span>
</pre></div>
</div>
<p>Has the same error handling as <a class="reference internal" href="#werkzeug.contrib.cache.BaseCache.get" title="werkzeug.contrib.cache.BaseCache.get"><code class="xref py py-meth docutils literal"><span class="pre">get()</span></code></a>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>keys</strong> – The function accepts multiple keys as positional
arguments.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="werkzeug.contrib.cache.BaseCache.inc">
<code class="descname">inc</code><span class="sig-paren">(</span><em>key</em>, <em>delta=1</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.contrib.cache.BaseCache.inc" title="Permalink to this definition">¶</a></dt>
<dd><p>Increments the value of a key by <cite>delta</cite>. If the key does
not yet exist it is initialized with <cite>delta</cite>.</p>
<p>For supporting caches this is an atomic operation.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>key</strong> – the key to increment.</li>
<li><strong>delta</strong> – the delta to add.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">The new value or <code class="docutils literal"><span class="pre">None</span></code> for backend errors.</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="werkzeug.contrib.cache.BaseCache.set">
<code class="descname">set</code><span class="sig-paren">(</span><em>key</em>, <em>value</em>, <em>timeout=None</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.contrib.cache.BaseCache.set" title="Permalink to this definition">¶</a></dt>
<dd><p>Add a new key/value to the cache (overwrites value, if key already
exists in the cache).</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>key</strong> – the key to set</li>
<li><strong>value</strong> – the value for the key</li>
<li><strong>timeout</strong> – the cache timeout for the key (if not specified,
it uses the default timeout).</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><code class="docutils literal"><span class="pre">True</span></code> if key has been updated, <code class="docutils literal"><span class="pre">False</span></code> for backend
errors. Pickling errors, however, will raise a subclass of
<code class="docutils literal"><span class="pre">pickle.PickleError</span></code>.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">boolean</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="werkzeug.contrib.cache.BaseCache.set_many">
<code class="descname">set_many</code><span class="sig-paren">(</span><em>mapping</em>, <em>timeout=None</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.contrib.cache.BaseCache.set_many" title="Permalink to this definition">¶</a></dt>
<dd><p>Sets multiple keys and values from a mapping.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>mapping</strong> – a mapping with the keys/values to set.</li>
<li><strong>timeout</strong> – the cache timeout for the key (if not specified,
it uses the default timeout).</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Whether all given keys have been set.</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">boolean</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
</div>
<div class="section" id="cache-systems">
<h2>Cache Systems<a class="headerlink" href="#cache-systems" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="werkzeug.contrib.cache.NullCache">
<em class="property">class </em><code class="descclassname">werkzeug.contrib.cache.</code><code class="descname">NullCache</code><span class="sig-paren">(</span><em>default_timeout=300</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.contrib.cache.NullCache" title="Permalink to this definition">¶</a></dt>
<dd><p>A cache that doesn’t cache. This can be useful for unit testing.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>default_timeout</strong> – a dummy parameter that is ignored but exists
for API compatibility with other caches.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="class">
<dt id="werkzeug.contrib.cache.SimpleCache">
<em class="property">class </em><code class="descclassname">werkzeug.contrib.cache.</code><code class="descname">SimpleCache</code><span class="sig-paren">(</span><em>threshold=500</em>, <em>default_timeout=300</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.contrib.cache.SimpleCache" title="Permalink to this definition">¶</a></dt>
<dd><p>Simple memory cache for single process environments. This class exists
mainly for the development server and is not 100% thread safe. It tries
to use as many atomic operations as possible and no locks for simplicity
but it could happen under heavy load that keys are added multiple times.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>threshold</strong> – the maximum number of items the cache stores before
it starts deleting some.</li>
<li><strong>default_timeout</strong> – the default timeout that is used if no timeout is
specified on <a class="reference internal" href="#werkzeug.contrib.cache.BaseCache.set" title="werkzeug.contrib.cache.BaseCache.set"><code class="xref py py-meth docutils literal"><span class="pre">set()</span></code></a>.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="class">
<dt id="werkzeug.contrib.cache.MemcachedCache">
<em class="property">class </em><code class="descclassname">werkzeug.contrib.cache.</code><code class="descname">MemcachedCache</code><span class="sig-paren">(</span><em>servers=None</em>, <em>default_timeout=300</em>, <em>key_prefix=None</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.contrib.cache.MemcachedCache" title="Permalink to this definition">¶</a></dt>
<dd><p>A cache that uses memcached as backend.</p>
<p>The first argument can either be an object that resembles the API of a
<code class="xref py py-class docutils literal"><span class="pre">memcache.Client</span></code> or a tuple/list of server addresses. In the
event that a tuple/list is passed, Werkzeug tries to import the best
available memcache library.</p>
<p>This cache looks into the following packages/modules to find bindings for
memcached:</p>
<blockquote>
<div><ul class="simple">
<li><code class="docutils literal"><span class="pre">pylibmc</span></code></li>
<li><code class="docutils literal"><span class="pre">google.appengine.api.memcached</span></code></li>
<li><code class="docutils literal"><span class="pre">memcached</span></code></li>
</ul>
</div></blockquote>
<p>Implementation notes: This cache backend works around some limitations in
memcached to simplify the interface. For example unicode keys are encoded
to utf-8 on the fly. Methods such as <a class="reference internal" href="#werkzeug.contrib.cache.BaseCache.get_dict" title="werkzeug.contrib.cache.BaseCache.get_dict"><code class="xref py py-meth docutils literal"><span class="pre">get_dict()</span></code></a> return
the keys in the same format as passed. Furthermore all get methods
silently ignore key errors to not cause problems when untrusted user data
is passed to the get methods which is often the case in web applications.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>servers</strong> – a list or tuple of server addresses or alternatively
a <code class="xref py py-class docutils literal"><span class="pre">memcache.Client</span></code> or a compatible client.</li>
<li><strong>default_timeout</strong> – the default timeout that is used if no timeout is
specified on <a class="reference internal" href="#werkzeug.contrib.cache.BaseCache.set" title="werkzeug.contrib.cache.BaseCache.set"><code class="xref py py-meth docutils literal"><span class="pre">set()</span></code></a>.</li>
<li><strong>key_prefix</strong> – a prefix that is added before all keys. This makes it
possible to use the same memcached server for different
applications. Keep in mind that
<a class="reference internal" href="#werkzeug.contrib.cache.BaseCache.clear" title="werkzeug.contrib.cache.BaseCache.clear"><code class="xref py py-meth docutils literal"><span class="pre">clear()</span></code></a> will also clear keys with a
different prefix.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="class">
<dt id="werkzeug.contrib.cache.GAEMemcachedCache">
<em class="property">class </em><code class="descclassname">werkzeug.contrib.cache.</code><code class="descname">GAEMemcachedCache</code><a class="headerlink" href="#werkzeug.contrib.cache.GAEMemcachedCache" title="Permalink to this definition">¶</a></dt>
<dd><p>This class is deprecated in favour of <a class="reference internal" href="#werkzeug.contrib.cache.MemcachedCache" title="werkzeug.contrib.cache.MemcachedCache"><code class="xref py py-class docutils literal"><span class="pre">MemcachedCache</span></code></a> which
now supports Google Appengine as well.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8: </span>Deprecated in favour of <a class="reference internal" href="#werkzeug.contrib.cache.MemcachedCache" title="werkzeug.contrib.cache.MemcachedCache"><code class="xref py py-class docutils literal"><span class="pre">MemcachedCache</span></code></a>.</p>
</div>
</dd></dl>
<dl class="class">
<dt id="werkzeug.contrib.cache.RedisCache">
<em class="property">class </em><code class="descclassname">werkzeug.contrib.cache.</code><code class="descname">RedisCache</code><span class="sig-paren">(</span><em>host='localhost'</em>, <em>port=6379</em>, <em>password=None</em>, <em>db=0</em>, <em>default_timeout=300</em>, <em>key_prefix=None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.contrib.cache.RedisCache" title="Permalink to this definition">¶</a></dt>
<dd><p>Uses the Redis key-value store as a cache backend.</p>
<p>The first argument can be either a string denoting address of the Redis
server or an object resembling an instance of a redis.Redis class.</p>
<p>Note: Python Redis API already takes care of encoding unicode strings on
the fly.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.</span></p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.8: </span><cite>key_prefix</cite> was added.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8: </span>This cache backend now properly serializes objects.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.3: </span>This cache backend now supports password authentication.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.10: </span><code class="docutils literal"><span class="pre">**kwargs</span></code> is now passed to the redis object.</p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>host</strong> – address of the Redis server or an object which API is
compatible with the official Python Redis client (redis-py).</li>
<li><strong>port</strong> – port number on which Redis server listens for connections.</li>
<li><strong>password</strong> – password authentication for the Redis server.</li>
<li><strong>db</strong> – db (zero-based numeric index) on Redis Server to connect.</li>
<li><strong>default_timeout</strong> – the default timeout that is used if no timeout is
specified on <a class="reference internal" href="#werkzeug.contrib.cache.BaseCache.set" title="werkzeug.contrib.cache.BaseCache.set"><code class="xref py py-meth docutils literal"><span class="pre">set()</span></code></a>.</li>
<li><strong>key_prefix</strong> – A prefix that should be added to all keys.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>Any additional keyword arguments will be passed to <code class="docutils literal"><span class="pre">redis.Redis</span></code>.</p>
</dd></dl>
<dl class="class">
<dt id="werkzeug.contrib.cache.FileSystemCache">
<em class="property">class </em><code class="descclassname">werkzeug.contrib.cache.</code><code class="descname">FileSystemCache</code><span class="sig-paren">(</span><em>cache_dir</em>, <em>threshold=500</em>, <em>default_timeout=300</em>, <em>mode=384</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.contrib.cache.FileSystemCache" title="Permalink to this definition">¶</a></dt>
<dd><p>A cache that stores the items on the file system. This cache depends
on being the only user of the <cite>cache_dir</cite>. Make absolutely sure that
nobody but this cache stores files there or otherwise the cache will
randomly delete files therein.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>cache_dir</strong> – the directory where cache files are stored.</li>
<li><strong>threshold</strong> – the maximum number of items the cache stores before
it starts deleting some.</li>
<li><strong>default_timeout</strong> – the default timeout that is used if no timeout is
specified on <a class="reference internal" href="#werkzeug.contrib.cache.BaseCache.set" title="werkzeug.contrib.cache.BaseCache.set"><code class="xref py py-meth docutils literal"><span class="pre">set()</span></code></a>.</li>
<li><strong>mode</strong> – the file mode wanted for the cache files, default 0600</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper"><p class="logo"><a href="../index.html">
<img class="logo" src="../_static/werkzeug.png" alt="Logo"/>
</a></p>
<h3><a href="../index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Cache</a><ul>
<li><a class="reference internal" href="#how-caching-works">How Caching Works</a></li>
<li><a class="reference internal" href="#creating-a-cache-object">Creating a Cache Object</a></li>
<li><a class="reference internal" href="#cache-system-api">Cache System API</a></li>
<li><a class="reference internal" href="#cache-systems">Cache Systems</a></li>
</ul>
</li>
</ul>
<h3>Related Topics</h3>
<ul>
<li><a href="../index.html">Documentation overview</a><ul>
<li><a href="index.html">Contributed Modules</a><ul>
<li>Previous: <a href="securecookie.html" title="previous chapter">Secure Cookie</a></li>
<li>Next: <a href="wrappers.html" title="next chapter">Extra Wrappers</a></li>
</ul></li>
</ul></li>
</ul>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/contrib/cache.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="../search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
© Copyright 2011, The Werkzeug Team.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
</div>
</body>
</html>
|