djangosnippets.org: Latest snippets tagged with 'memcached'http://djangosnippets.org/tags/memcached/2012-06-27T06:31:40.823222-05:00Cache Backend using memcached including prefix settings
2012-06-27T06:31:40.823222-05:00mojemeno123http://djangosnippets.org/snippets/2781/<p>Django later than 1.3 (not sure of exact version) wasn't using prefix settings in cache tags or functions used in views. Just for whole page caching. This is small custom cache snippet based on memcached.CacheClass. Feel free adding any comments.</p>
Freely redistributableJSON instead of pickle for memcached
2012-01-10T16:21:06.401532-06:00divermanhttp://djangosnippets.org/snippets/2642/<p>Standard memcache client uses pickle as a serialization format. It can be handy to use json, especially when another component (e.g. backend) doesn't know pickle, but json yes.</p>
Freely redistributableProperty Attributes in Memcache
2011-10-27T13:12:12.230742-05:00orihttp://djangosnippets.org/snippets/2582/<h2>Memcached Property Attributes</h2>
<p>Setting the attribute will store the value in memcached; accessing the attribute will retrieve from memcached. Most useful as a way of simulating memcached "fields" on model instances. See the docstring for details.</p>
Freely redistributableMethod Caching
2011-07-01T14:50:31.483559-05:00bryanhelmighttp://djangosnippets.org/snippets/2477/<p>A very simple decorator that caches both on-class and in memcached:</p>
<pre><code>@method_cache(3600)
def some_intensive_method(self):
return # do intensive stuff`
</code></pre>
<p>Alternatively, if you just want to keep it per request and forgo memcaching, just do:</p>
<pre><code>@method_cache()
def some_intensive_method(self):
return # do intensive stuff`
</code></pre>
Freely redistributableA simple client to get some info (NOT values...) from memcached
2009-06-17T15:49:31.720971-05:00pterkhttp://djangosnippets.org/snippets/1573/<p>Simple client to get some stats from memcached.</p>
Freely redistributableUsing another memcached for sessions
2008-11-15T09:01:00.195816-06:00dipankarsarkarhttp://djangosnippets.org/snippets/1191/<p>This solves the problem of losing sessions data when you restart memcached. So you use a different memcached instance for sessions which you rarely restart.</p>
<p>Use the above code and add the following to you settings.py</p>
<pre><code>SESSION_ENGINE = "kwippyproject.session_backend"
SESSION_CACHE = 'memcached://127.0.0.1:11200/'
</code></pre>
<p>(Above assumes that your session's memcached is running …</p>
Freely redistributableTest and Restart Memcached Server
2008-10-23T11:57:32.917575-05:00Digitalxerohttp://djangosnippets.org/snippets/1152/<p>Request-phase cache middleware that checks to make sure the Cache server is running. Starting it if it is not. This is run for every request, it checks to see if it can get a defined item out of the cache, if that fails it tries to set it. Failing that …</p>
Freely redistributableMintCache (simple version)
2008-06-10T18:38:58.240450-05:00disqushttp://djangosnippets.org/snippets/793/<p>This is intended as an alternative to http://www.djangosnippets.org/snippets/155/</p>
<p>Put this in your own cache.py and import it instead of django.core.cache and use it the same way. We left out the "add" function but it shouldn't be too hard to make if you want it.</p>
<p>From the above post: "The purpose …</p>
Freely redistributablecache_smart template tag
2008-02-24T08:24:31.986736-06:00michiel_1981http://djangosnippets.org/snippets/614/<p>cache_smart template tag is a drop in replacement for default cache tag by Django but with the added bonus to be more resistant against dog-pile/stampeding effect.
</p>
<p>This snippet uses a extra cache entry to store a stale time so we don't have to pickle/unpickle to store this extra value.
If …</p>
Freely redistributableCheck Size of Object in memcached
2007-11-27T13:23:43.678769-06:00deryckhttp://djangosnippets.org/snippets/488/<p>I've been working with a data set where a single object won't fit into memcached's 1 Mb slab limit. The two functions have been useful to me for debugging the size of the data structure once pickled, and if said pickled data structure is greater than 1 Mb.
</p>
<p>These functions …</p>
Freely redistributableMintCache
2007-04-04T23:54:41.787836-05:00gfranxmanhttp://djangosnippets.org/snippets/155/<p>MintCache is a caching engine for django that allows you to get by with stale data while you freshen your breath, so to speak.
</p>
<p>The purpose of this caching scheme is to avoid the dog-pile effect. Dog-piling is what normally happens when your data for the cache takes more time …</p>
Freely redistributable