|
Usage
How to use the JsMemcached client api.
Featured Setup
<script type="text/javascript" runat="server" src="path/to/JsMemcached.js"></script> UsageAdding the script tag to the page makes available a global singleton object called JsMemcached. Use this object as your starting point for all memcache communication. This object internally uses Jaxer.Socket to communicate directly with the memcached server. APINote: Performance optimization has been a huge pita, because of the performance of the Jaxer runtime (or because of my inability to write better code). To keep performance as optimal as possible, I've had to remove almost all of the validation code. So, please ensure that you validate your parameters to the JsMemcached methods before you send it. ConfigurationIn most cases, you'll be using JsMemcached on the same server as your application and on port 11211. If that's the case, you don't need to do anything - the default configuration in JsMemcached will do. However, if you want to change the settings, this is how you do it: JsMemcached.config("cache.mydomain.com", 12345);You could also use an explicit IP address instead of cache.mydomain.com above. The storage commands: .add, .set and .replaceAll these commands will save a value associated with the key in the memcached server. Example: JsMemcached.add(key, value, time);
If the conditions above are not met, JsMemcached throws an error which will contain what the server said when performing the save operation.
Returns: Nothing. The retrieval command: .getThis command retrieves data from the memcached server. Example: JsMemcached.get(key); The key parameter should match something stored before in the memcached server. Returns: The value corresponding to the key in the memcached server. If no match is found, an empty string is returned. Note: If there's anyone who can take a look at the source, and find a way to optimize the string processing in this get call, and make it bullet-proof, please let me know. Though this call is already faster than a corresponding DB call, it's still about thrice as slow as other memcached clients. I would guess part of this problem is because of the runtime (Tamarin, where are you!), but any help will undoubtedly be great. Wait, that's it?For now, yes. I will be working on making this API complete with the memcached protocol specs, and intend to roll it out soon. Meanwhile, in a parallel thought, I'm worried about the performance of this thing, and want to make sure I'm using the processor juice as optimally as possible. I could do with some help to make this thing faster. Is there anybody out there? | ||||||||||||