Introduction memcached

The module MemCache provides a client api to a memcached server. memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.

This module uses apr_memcache. apr_memcache depends on the Apache Portable Runtime (apr). This means that this module only works when libapr-1.dll, libapriconv-1.dll and libaprutil-1.dll are available. When you have Apache installed, you can find these files in the Apache bin directory.

How memcached works can be read at the memcached website

memcached in JavaScript

Using memcached in wxJavaScript is easy. Create a Client object and add a memcached server. When you set properties to the client object, a value will be stored in the cache. When you retrieve properties, a value will be retrieved from the cache. The key used to get the value, is the name of the property.

var client = new memcache.Client();
client.addServer("127.0.0.1", 11211);
client.username = "franky";
print(client.username, "\n");

It is not possible to store a JavaScript object directly into the cache. The object will always be converted to a String. Instead JSON can be a good alternative to store an object into the cache.

The following sample shows how you can use memcached to cache information for a webpage.

var cache = new memcache.Client();

cache.addServer("127.0.0.1", 11211);
var name = cache.username;
if ( name )
{
  response.print("<h1>Hello ", name, "</h1>");
}
else
{
  cache.username = "Franky";
  response.print("The name is set, please refresh this page!");
}

When you use the name of a user as part of the key, it is possible to create some kind of session management in memcached.

SourceForge.net Logo Support This Project

All Classes

memcache.Client

Design downloaded from Zeroweb.org: Free website templates, layouts, and tools.