Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Python by (12.7k points)

I'm composing a web application utilizing Python and the structure/framework, and I need to utilize memcached all through. 

I've been looking through the web attempting to track down some great documentation on the python-memcached module, yet everything I could discover was this example on the MySQL site, and the documentation on its strategies isn't extraordinary.

1 Answer

0 votes
by (26.4k points)

It's genuinely straightforward. You compose values utilizing keys and expiry times. You get values utilizing keys. You can lapse keys from the framework. 

Most customers adhere to similar standards. You can peruse the generic guidelines and best practices on the memcached home page

On the off chance that you truly need to dive into it, I'd take a gander at the source. Here's the header remark:


client module for memcached (memory cache daemon)



See U{the MemCached homepage<>} for more about memcached.

Usage summary


This should give you a feel for how this module operates::

    import memcache

    mc = memcache.Client([''], debug=0)

    mc.set("some_key", "Some value")

    value = mc.get("some_key")

    mc.set("another_key", 3)


    mc.set("key", "1")   # note that the key used for incr/decr must be a string.



The standard way to use memcache with a database is like this::

    key = derive_key(obj)

    obj = mc.get(key)

    if not obj:

        obj = backend_api.get(...)

        mc.set(key, obj)

    # we now have obj, and future passes through this code

    # will use the object from the cache.

Detailed Documentation


More detailed documentation is available in the L{Client} class.


Are you pretty much interested to learn python in detail? Come and join the python training course to gain more knowledge.

For more details, do check out the below video tutorial...

Browse Categories