JSMemcached ClientThis project aims to create a feature complete JavaScript client for memcached that can be used over Jaxer. DependenciesSetupFirstly, include the script. <script type="text/javascript" src="path/to/jsMemcached.js" runat="server"></script> Note: runat attribute can only have the value "server". Anything else will be very funny. Alternatively, if you are using jsMemcached-extension.js, you simply have to drop the file into your jaxer installation's extensions folder, restart Jaxer Manager, and you are set. UsageFirstly, configure JsMemcached to work with your server. To do this, you should simply call .configure on the JsMemcached object, and pass it your memcache server host and port. For jsMemcached.js: JsMemcached.configure("localhost", 11211);For jsMemcached-extension.js: Jaxer.memcached.configure("localhost", 11211);The operations on JsMemcached and Jaxer.memcached are identical. For brevity from this point on, we'll use the term JsMemcached for both objects. All the methods described below can also be applied to Jaxer.memcached. To save a value to memcached, simply use the following code: JsMemcached.set("keyName", "Value here, as long as you want");To retrieve the value: JsMemcached.get("keyName");To cleanup, whenever you are done with the JSMemcached object, you should call: JsMemcached.close(); Note that there's no corresponding .open() method to open a connection to the memcached server. Connections are lazy-opened when the first write/retrieval call is made. Once that's done, the connection is held open till .close() is called. Features- Lazy connect to the memcached server only on demand.
- Once connected, doesn't disconnect unless explicitly asked to. This reduces the overhead of connection-establishing to the memcached server.
- Uses native Jaxer.Socket which is (hopefully) very fast.
Known issues- Not feature complete. Only the following methods are currently supported: add, set, replace, get, deleteKey. The rest of the features will be added soon.
- Doesn't currently support connection pooling and any form of sharding between multiple memcache server instances. This can be added depending on feedback.
|