{"id":15572943,"url":"https://github.com/ratson/cacheman-mongodb","last_synced_at":"2025-10-24T07:14:43.479Z","repository":{"id":57192560,"uuid":"90738248","full_name":"ratson/cacheman-mongodb","owner":"ratson","description":null,"archived":false,"fork":false,"pushed_at":"2019-04-20T12:08:50.000Z","size":55,"stargazers_count":0,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-09T12:33:37.086Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ratson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-09T11:30:30.000Z","updated_at":"2019-04-20T12:08:52.000Z","dependencies_parsed_at":"2022-08-24T03:10:32.896Z","dependency_job_id":null,"html_url":"https://github.com/ratson/cacheman-mongodb","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ratson%2Fcacheman-mongodb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ratson%2Fcacheman-mongodb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ratson%2Fcacheman-mongodb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ratson%2Fcacheman-mongodb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ratson","download_url":"https://codeload.github.com/ratson/cacheman-mongodb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246149882,"owners_count":20731405,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T18:08:56.231Z","updated_at":"2025-10-24T07:14:38.443Z","avatar_url":"https://github.com/ratson.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cacheman-mongodb\n\n[![NPM version](https://badge.fury.io/js/cacheman-mongodb.png)](http://badge.fury.io/js/cacheman-mongodb)\n\nMongoDB standalone caching library for Node.JS and also cache engine for [cacheman](https://github.com/cayasso/cacheman).\n\n## This is a fork\n\nFork from https://github.com/cayasso/cacheman-mongo with the following differences,\n\n- Removed `pre-commit` from `dependencies`.\n- Updated `dependencies`.\n\n## Instalation\n\n``` bash\nnpm install cacheman-mongodb --save\n```\n\n## Usage\n\n```javascript\nvar CachemanMongo = require('cacheman-mongodb');\nvar cache = new CachemanMongo();\n\n// set the value\ncache.set('my key', { foo: 'bar' }, function (error) {\n\n  if (error) throw error;\n\n  // get the value\n  cache.get('my key', function (error, value) {\n\n    if (error) throw error;\n\n    console.log(value); //-\u003e {foo:\"bar\"}\n\n    // delete entry\n    cache.del('my key', function (error){\n\n      if (error) throw error;\n\n      console.log('value deleted');\n    });\n\n  });\n});\n```\n\n## API\n\n### CachemanMongo([options])\n\nCreate `cacheman-mongodb` instance. `options` are mongo valid options including `port`, `host`, `database` and `collection`.\n\n```javascript\nvar options = {\n  port: 9999,\n  host: '127.0.0.1',\n  username: 'beto',\n  password: 'my-p@ssw0rd'\n  database: 'my-cache-db',\n  collection: 'my-collection',\n  compression: false\n};\n\nvar cache = new CachemanMongo(options);\n```\n\nYou can also pass a valid mongodb connection string as first arguments like this:\n\n```javascript\nvar options = {\n  collection: 'account'\n};\n\nvar cache = new CachemanMongo('mongodb://127.0.0.1:27017/blog', options);\n```\n\nOr pass a mongodb db instance directly as client:\n\n```javascript\nMongoClient.connect('mongodb://127.0.0.1:27017/blog', function (err, db) {\n  var cache = new CachemanMongo(db, { collection: 'account' });\n\n  // or\n  cache = new CachemanMongo({ client: db, collection: 'account' });\n});\n```\n\n#### Cache Value Compression\n\nMongoDB has a 16MB document size limit, and, currently, does not have built in support for compression. You can enable cache value compression for large Buffers by setting the `compression` options to `true`, this will use the native node `zlib` module to compress with `gzip`. It only compresses Buffers because of the complexity in correctly decompressing and deserializing the variety of data structures and string encodings.\n\nThanks to @Jared314 for adding this [feature](https://github.com/cayasso/cacheman-mongo/pull/2).\n\n```javascript\nvar cache = new Cache({ compression: true });\ncache.set('test1', new Buffer(\"something big\"), function (err) {...});\n\n```\n### cache.set(key, value, [ttl, [fn]])\n\nStores or updates a value.\n\n```javascript\ncache.set('foo', { a: 'bar' }, function (err, value) {\n  if (err) throw err;\n  console.log(value); //-\u003e {a:'bar'}\n});\n```\n\nOr add a TTL(Time To Live) in seconds like this:\n\n```javascript\n// key will expire in 60 seconds\ncache.set('foo', { a: 'bar' }, 60, function (err, value) {\n  if (err) throw err;\n  console.log(value); //-\u003e {a:'bar'}\n});\n```\n\n### cache.get(key, fn)\n\nRetreives a value for a given key, if there is no value for the given key a null value will be returned.\n\n```javascript\ncache.get('foo', function (err, value) {\n  if (err) throw err;\n  console.log(value);\n});\n```\n\n### cache.del(key, [fn])\n\nDeletes a key out of the cache.\n\n```javascript\ncache.del('foo', function (err) {\n  if (err) throw err;\n  // foo was deleted\n});\n```\n\n### cache.clear([fn])\n\nClear the cache entirely, throwing away all values.\n\n```javascript\ncache.clear(function (err) {\n  if (err) throw err;\n  // cache is now clear\n});\n```\n\n## Run tests\n\n``` bash\n$ make test\n```\n\n## License\n\n(The MIT License)\n\nCopyright (c) 2015 Jonathan Brumley \u0026lt;cayasso@gmail.com\u0026gt;\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fratson%2Fcacheman-mongodb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fratson%2Fcacheman-mongodb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fratson%2Fcacheman-mongodb/lists"}