{"_id":"memcached-mock","_rev":"9-5152cd99a707903c401aae099e0142b0","name":"memcached-mock","description":"A mock implementation of memcached to use as a replacement in tests","dist-tags":{"latest":"0.1.0"},"versions":{"0.0.1":{"name":"memcached-mock","version":"0.0.1","description":"A mock implementation of memcached to use as a replacement in tests","keywords":["cache","client","memcache","memcached","mock","tdd","test","unit"],"main":"index.js","scripts":{"test":"bin/test"},"homepage":"https://github.com/jeffreyhunter77/memcached-mock","bugs":{"url":"https://github.com/jeffreyhunter77/memcached-mock/issues"},"author":{"name":"Jeffrey Hunter","email":"jeff@missioncriticallabs.com"},"license":"MIT","repository":{"type":"git","url":"git://github.com:jeffreyhunter77/memcached-mock.git"},"devDependencies":{"nodeunit":"0.9.0"},"gitHead":"cb8acd7f4068f296758856b2b2e701e72fc16470","_id":"memcached-mock@0.0.1","_shasum":"99ab42f726702dbc18ac01b0b7464f338895d483","_from":".","_npmVersion":"2.5.1","_nodeVersion":"0.12.0","_npmUser":{"name":"jeffreyhunter77","email":"jeffrey_hunter@cable.comcast.com"},"maintainers":[{"name":"jeffreyhunter77","email":"jeffrey_hunter@cable.comcast.com"}],"dist":{"shasum":"99ab42f726702dbc18ac01b0b7464f338895d483","tarball":"https://registry.npmjs.org/memcached-mock/-/memcached-mock-0.0.1.tgz","integrity":"sha512-wpjpHnkSDMiOP8+IY5d3rWh6o0yzHAXkFNI8N1Nbtu/3J2srT4rf3i5B1yRNhITR+aBdPZQFWR4GabRRh3MVLg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDocMJ5me6VLhHbZFHPbzaDNwyMoi5bfWQibUxZ0UDu7wIhAKJiF8fc1kksZqbCIrepScC1F1AbnUYfsVcpADkNsGmy"}]}},"0.0.2":{"name":"memcached-mock","version":"0.0.2","description":"A mock implementation of memcached to use as a replacement in tests","keywords":["cache","client","memcache","memcached","mock","tdd","test","unit"],"main":"index.js","scripts":{"test":"bin/test"},"homepage":"https://github.com/jeffreyhunter77/memcached-mock","bugs":{"url":"https://github.com/jeffreyhunter77/memcached-mock/issues"},"author":{"name":"Jeffrey Hunter","email":"jeff@missioncriticallabs.com"},"license":"MIT","repository":{"type":"git","url":"git://github.com:jeffreyhunter77/memcached-mock.git"},"devDependencies":{"nodeunit":"0.9.0"},"gitHead":"0be35763b2bdc5b03395fd815be447d2d64dd7b6","_id":"memcached-mock@0.0.2","_shasum":"42895f8b3deb45dfad8eee83150c638b17547962","_from":".","_npmVersion":"2.5.1","_nodeVersion":"0.12.0","_npmUser":{"name":"jeffreyhunter77","email":"jeffrey_hunter@cable.comcast.com"},"maintainers":[{"name":"jeffreyhunter77","email":"jeffrey_hunter@cable.comcast.com"}],"dist":{"shasum":"42895f8b3deb45dfad8eee83150c638b17547962","tarball":"https://registry.npmjs.org/memcached-mock/-/memcached-mock-0.0.2.tgz","integrity":"sha512-hXS8h6hSSIw5A62rr52I7sNPi/Fp+GZllM7Bt69/vC8osgqTVASNHEicN8B7RbphmcOsWObfSMQDcXqRfvpjsw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDEL6T4m6sqKnIY0rT79bhmXzdkg84VLI6m2Yy/LQRmKwIgR2x9WDiFEGczYWYSv+vAKGaG5e5qgZs/IW3k4khAkxs="}]}},"0.0.3":{"name":"memcached-mock","version":"0.0.3","description":"A mock implementation of memcached to use as a replacement in tests","keywords":["cache","client","memcache","memcached","mock","tdd","test","unit"],"main":"index.js","scripts":{"test":"bin/test"},"homepage":"https://github.com/jeffreyhunter77/memcached-mock","bugs":{"url":"https://github.com/jeffreyhunter77/memcached-mock/issues"},"author":{"name":"Jeffrey Hunter","email":"jeff@missioncriticallabs.com"},"license":"MIT","repository":{"type":"git","url":"git://github.com:jeffreyhunter77/memcached-mock.git"},"devDependencies":{"nodeunit":"0.9.0"},"gitHead":"7c4dcfe9464b9b20416ce28b5a3b12f0e905461c","_id":"memcached-mock@0.0.3","_shasum":"b1afd40e185e5c116f019650b7a4c7727f5a9c68","_from":".","_npmVersion":"2.5.1","_nodeVersion":"0.12.0","_npmUser":{"name":"jeffreyhunter77","email":"jeffrey_hunter@cable.comcast.com"},"maintainers":[{"name":"jeffreyhunter77","email":"jeffrey_hunter@cable.comcast.com"}],"dist":{"shasum":"b1afd40e185e5c116f019650b7a4c7727f5a9c68","tarball":"https://registry.npmjs.org/memcached-mock/-/memcached-mock-0.0.3.tgz","integrity":"sha512-xAduSkU/Eb8ep3qoR2mMM2saZEiYINz9lBbYiCcAanink9xohAakNx5RHCyCUVhap9t6pIXM8YHze3DfHCPL9g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIE0iJMEZM43kIAlankd4c+14Bfxmqep5AW7k/k/a+dR1AiEApzuO5YgncUYStHfazxNrqcV5Yq7Ip6durQeJpPcghuQ="}]}},"0.1.0":{"name":"memcached-mock","version":"0.1.0","description":"A mock implementation of memcached to use as a replacement in tests","keywords":["cache","client","memcache","memcached","mock","tdd","test","unit"],"main":"index.js","scripts":{"test":"bin/test"},"homepage":"https://github.com/jeffreyhunter77/memcached-mock","bugs":{"url":"https://github.com/jeffreyhunter77/memcached-mock/issues"},"author":{"name":"Jeffrey Hunter","email":"jeff@missioncriticallabs.com"},"license":"MIT","repository":{"type":"git","url":"git://github.com:jeffreyhunter77/memcached-mock.git"},"devDependencies":{"nodeunit":"0.9.0","istanbul":"0.3.13"},"gitHead":"38caa5f878eb6a43a8ec038fa1eedf6951948a0f","_id":"memcached-mock@0.1.0","_shasum":"3d53d7fbb4ac1e7417c4c363f436b909d3653132","_from":".","_npmVersion":"2.5.1","_nodeVersion":"0.12.0","_npmUser":{"name":"jeffreyhunter77","email":"jeffrey_hunter@cable.comcast.com"},"maintainers":[{"name":"jeffreyhunter77","email":"jeffrey_hunter@cable.comcast.com"}],"dist":{"shasum":"3d53d7fbb4ac1e7417c4c363f436b909d3653132","tarball":"https://registry.npmjs.org/memcached-mock/-/memcached-mock-0.1.0.tgz","integrity":"sha512-QzFm8eoMpYSKDXdI7a7InOe0Gg4QBC7e93+6R6OCjKGIoFs31vhfgnM386ZT2b6O0hpPQhesnlSalBTqaNOVnQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICOyutDxQEdboP+rj6XAqfnjZYe1Kw0dE+Zy/kg8/jdcAiBIx7krhFvs6OmWHabYdumqT7UOJzdXocXRXRxsWUI8lw=="}]}}},"readme":"# memcached-mock\n\nA mock implementation of [memcached](https://www.npmjs.com/package/memcached) to use as a replacement in tests.\n\nThis is an in-memory implementation. It implements the documented, public API of the `memcached` module (and known aliases). The interface is the same, however, no network calls are made. Values are stored in memory and discarded when the process exits.\n\n## Getting Started\n\n### Installation\n\nInstall the module with npm:\n\n```\nnpm install memcached-mock\n```\n\n### Usage\n\nUse `memcached-mock` the same as if it were `memcached`:\n\n```javascript\nvar Memcached = require('memcached-mock');\n\nvar memcached = new Memcached('localhost:11211');\n\nmemcached.set(\"hello\", \"world!\", 60, function(err) {\n  \n  if (!err)\n    memcached.get(\"hello\", function(err, data) {\n      console.log(data); // prints: world!\n    });\n\n});\n```\n\nIf your code does not allow you to easily replace the instance of Memcached being used for testing, you may choose to use a tool like [proxyquire](https://www.npmjs.com/package/proxyquire). That would look something like the following.\n\n**lib/cache.js:**\n\n```javascript\nvar Memcached = require('memcached');\n\n// ...\n```\n\n**test/unit/cache.js:**\n\n```javascript\nvar proxyquire = require('proxyquire')\n  , memcachedMock = require('memcached-mock')\n;\n\nmodule.exports.testSomething = function(done) {\n  var cache = proxyquire('../../lib/cache', {memcached: memcachedMock});\n  \n  // continue with test...\n}\n```\n\n## Limitations\n\nThis module is intended to work as a drop-in replacement in simple use cases. It allows you to provide a known, deterministic state for your tests. It might also serve as a starting point for more complex interactions. Some simulations, however, may require extra work.\n\nMethods for accessing server information (such as `stats` or `settings`), for example, are mostly stubs that always return the same data. If you'd like to return different data, you'll need to provide your own replacements for those. Similarly, the methods for getting and setting cache values are fully functional, but if you'd like to simulate something beyond a connection to a single cache cluster, at a minimum you'll need to set up your Memcached instances to use the appropriate cache object for their server connection settings. By default, server strings are not examined and all instances share the same cache store. See documentation on the `cache()` method for more details.\n\n## Asynchronous Callbacks\n\nThe work of making any cache updates is done synchronously. So, for example, take this code:\n\n```javascript\nvar memcached = new Memcached(\"127.0.0.1:11211\");\n\nmemcached.set(\"foo\", \"bar\", 0, function() { /* ... */ });\n\nmemcached.get(\"foo\", function(err, data) {\n  console.log(\"foo=%s\", data); // prints: foo=bar\n});\n```\n\nThat will work because the cached has been updated by the time the call to the `set` method returns. Note, however, that callbacks are always invoked asynchronously. This is essential for testing the behavior your code will see from an actual connection to memcached. That means that this code will not work:\n\n```javascript\nvar memcached = new Memcached(\"127.0.0.1:11211\");\n\nmemcached.flush(function() {\n  memcached.set(\"bar\", \"foo\", 0, function() { /* ... */ });\n});\n\nmemcached.get(\"bar\", function(err, data) {\n  console.log(\"bar=%s\", data); // bar has not been set yet!\n});\n```\n\nYou may choose to exploit this fact in your tests. You can, for example, safely flush a cache in your setup or teardown code without waiting for the callback to be invoked.\n\n## API\n\n### Constructor\n\n#### new Memcached(serverLocations, options)\n\n  * `serverLocations`: **String**, **Array**, or **Object** Simulated connections\n  * `options`: **Object** Client options\n\nConstructs a new mock Memcached instance. This simulates the interface of Memcached, but most settings do not have an effect. No connections are established with a server, and the value of `serverLocations` does not change the behavior of the mock. The only option that does have an effect is `maxExpiration`, which alters how TTL values are interpreted.\n\n### Public Instance Methods\n\n\n#### memcached.add(key, value, ttl, callback)\n\n * `key`: **String** Name of the key\n * `value`: **Mixed** Value to associate with the key\n * `ttl`: **Number** Expiration time for the key in seconds\n * `callback`: **Function** On completion callback\n\nAdd a new mapping if the key does not yet exist in the cache.\n\n#### memcached.append(key, value, callback)\n\n * `key`: **String** Name of the key\n * `value`: **Mixed** The value to append\n * `callback`: **Function** On completion callback\n\nAppend data to an existing key's value. The key must already exist in the cache.\n\n#### memcached.cache()\n\nThis method is not part of the `memcached` interface. It provides direct access to the underlying in-memory cache. Values in the cache object are also objects with the following properties:\n\n * **value** - The stored value\n * **expires** - The time in milliseconds when this entry expires\n * **cas** - The CAS id of the entry\n\nThis can be used to directly alter or verify the contents of the cache. For example, if in a unit test you wanted to verify that the key \"session-1\" contained the object `{userId: 2}`, that verification code might look like:\n\n```javascript\nvar cache = memcached.cache();\n\nassert.deepEqual(cache[\"session-1\"].value, {userId: 2});\n```\n\n#### memcached.cache(cacheObject)\n\n * `cacheObject`: **Object** The cache object to use\n\nThis method is not part of the `memcached` interface. It allows individual mock instances of Memcached to be configured to use a specific cache object instead of the default global cache.\n\nThis allows you to write code like:\n\n```javascript\nvar memcachedA = new Memcached('192.168.0.1:11211');\nvar memcachedB = new Memcached('192.168.0.2:11211');\nvar memcachedC = new Memcached('192.168.0.2:11211');\n\nvar cache1 = {};\nvar cache2 = {};\n\nmemcachedA.cache(cache1); // set the cache object\nmemcachedB.cache(cache2);\nmemcachedC.cache(cache2);\n```\n\nThis will set up `memcachedA` to use `cache1`, and `memcachedB` and `memcachedC` to use `cache2`, mimicking the behavior their server settings would normally have.\n\n#### memcached.cachedump(server, slabid, limit, callback)\n\n * `server`: **String** Server to return the dump of\n * `slabid`: **Number** The slab id to dump\n * `limit`: **Number** The maximum number of results to return\n * `callback`: **Function** On completion callback\n\nProvides a list of the keys in the cache. This mock method does return a listing of the actual keys, modeled as a single slab. All arguments besides `callback` are ignored.\n\n#### memcached.cas(key, value, cas, ttl, callback)\n\n * `key`: **String** Name of the key\n * `value`: **Mixed** Value to associate with the key\n * `cas`: **String** The CAS id to compare\n * `ttl`: **Number** Expiration time for the key in seconds\n * `callback`: **Function** On completion callback\n\nUpdate a mapping, but only if the CAS id of `key` matches `cas`. The CAS id of a key changes every time the key is updated.\n\n#### memcached.decr(key, amount, callback)\n\n * `key`: **String** Name of the key\n * `amount`: **Number** Amount to decrement the value by\n * `callback`: **Function** On completion callback\n\nDecrement a key's value by `amount`. This is only successful if the key already exists.\n\n#### memcached.del(key, callback)\n\n * `key`: **String** Name of the key\n * `callback`: **Function** On completion callback\n\nRemove a key from the cache.\n\n#### memcached.delete(key, callback)\n\nAlias of `del()`.\n\n#### memcached.end()\n\nTerminate the server connection. This method has no effect.\n\n#### memcached.flush(callback)\n\n * `callback`: **Function** On completion callback\n\nFlush all keys from the cache.\n\n#### memcached.flushAll(callback)\n\nAlias of `flush()`.\n\n#### memcached.get(key, callback)\n\n * `key`: **String** Name of the key\n * `callback`: **Function** On completion callback\n\nRetrieve the value associated with `key`. If `key` is an array, this will automatically perform a `getMulti` call instead.\n\n#### memcached.gets(key, callback)\n\n * `key`: **String** Name of the key\n * `callback`: **Function** On completion callback\n\nRetrieve the value associated with `key` and its CAS id.\n\n#### memcached.getMulti(keys, callback)\n\n * `keys`: **Array** Array of key names\n * `callback`: **Function** On completion callback\n\nRetrieve the value associated with multiple keys in a single call.\n\n#### memcached.incr(key, amount, callback)\n\n * `key`: **String** Name of the key\n * `amount`: **Number** Amount to increment the value by\n * `callback`: **Function** On completion callback\n\nIncrement a key's value by `amount`. This is only successful if the key already exists.\n\n#### memcached.items(callback)\n\n * `callback`: **Function** On completion callback\n\nObtain information about items stored in the server. This returns correct information about the number of items contained in the cache. All other information is stub data.\n\n#### memcached.prepend(key, value, callback)\n\n * `key`: **String** Name of the key\n * `value`: **Mixed** The value to prepend\n * `callback`: **Function** On completion callback\n\nPrepend data to an existing key's value. The key must already exist in the cache.\n\n#### memcached.replace(key, value, ttl, callback)\n\n * `key`: **String** Name of the key\n * `value`: **Mixed** New value to associate with the key\n * `ttl`: **Number** Expiration time for the key in seconds\n * `callback`: **Function** On completion callback\n\nReplace the existing value of `key` with `value`. This is only successful if `key` already exists in the cache.\n\n#### memcached.set(key, value, ttl, callback)\n\n * `key`: **String** Name of the key\n * `value`: **Mixed** Value to associate with the key\n * `ttl`: **Number** Expiration time for the key in seconds\n * `callback`: **Function** On completion callback\n\nSet the value associated with `key` in the cache. This works whether the key already exists in the cache or not.\n\n#### memcached.settings(callback)\n\n * `callback`: **Function** On completion callback\n\nRetrieve server settings. This returns stub data for each server given in the constructor.\n\n#### memcached.slabs(callback)\n\n * `callback`: **Function** On completion callback\n\nRetrieve server slab information. This returns stub data showing one slab for each server given in the constructor.\n\n#### memcached.stats(callback)\n\n * `callback`: **Function** On completion callback\n\nRetrieve server stats. This returns stub data for each server given in the constructor.\n\n#### memcached.statsItems(callback)\n\nAlias of `items()`.\n\n#### memcached.statsSettings(callback)\n\nAlias of `settings()`.\n\n#### memcached.statsSlabs(callback)\n\nAlias of `slabs()`.\n\n#### version(callback)\n\n * `callback`: **Function** On completion callback\n\nRetrieve server version. This returns stub data for each server given in the constructor. The current version of the module reports itself as version 1.4.20.\n","maintainers":[{"name":"jeffreyhunter77","email":"jeffrey_hunter@cable.comcast.com"}],"time":{"modified":"2022-06-19T17:42:53.805Z","created":"2015-02-23T01:03:29.995Z","0.0.1":"2015-02-23T01:03:29.995Z","0.0.2":"2015-02-25T04:27:34.057Z","0.0.3":"2015-03-05T02:53:50.545Z","0.1.0":"2015-04-01T04:35:55.630Z"},"homepage":"https://github.com/jeffreyhunter77/memcached-mock","keywords":["cache","client","memcache","memcached","mock","tdd","test","unit"],"repository":{"type":"git","url":"git://github.com:jeffreyhunter77/memcached-mock.git"},"author":{"name":"Jeffrey Hunter","email":"jeff@missioncriticallabs.com"},"bugs":{"url":"https://github.com/jeffreyhunter77/memcached-mock/issues"},"license":"MIT","readmeFilename":"README.md"}