{"id":19324346,"url":"https://github.com/aalfiann/recachegoose","last_synced_at":"2025-04-05T03:10:34.763Z","repository":{"id":38382257,"uuid":"324277347","full_name":"aalfiann/recachegoose","owner":"aalfiann","description":"A Mongoose caching module that works exactly how you would expect it to, with the latest version of Mongoose.","archived":false,"fork":false,"pushed_at":"2024-12-03T10:53:46.000Z","size":189,"stargazers_count":28,"open_issues_count":0,"forks_count":14,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T02:07:19.445Z","etag":null,"topics":["cacheman","cacheman-engine","mongoose","mongoose-cache","mongoose-caching","recacheman"],"latest_commit_sha":null,"homepage":"https://nodei.co/npm/recachegoose","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aalfiann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-25T03:07:41.000Z","updated_at":"2025-03-27T15:44:36.000Z","dependencies_parsed_at":"2024-06-09T16:52:14.824Z","dependency_job_id":"87b495b6-0e0d-46b4-b47c-a51f1e324615","html_url":"https://github.com/aalfiann/recachegoose","commit_stats":{"total_commits":50,"total_committers":8,"mean_commits":6.25,"dds":"0.19999999999999996","last_synced_commit":"a4722f2c4e3dd3e911154e4f9ffd044c2a84ca72"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aalfiann%2Frecachegoose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aalfiann%2Frecachegoose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aalfiann%2Frecachegoose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aalfiann%2Frecachegoose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aalfiann","download_url":"https://codeload.github.com/aalfiann/recachegoose/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247280272,"owners_count":20912967,"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":["cacheman","cacheman-engine","mongoose","mongoose-cache","mongoose-caching","recacheman"],"created_at":"2024-11-10T02:04:46.588Z","updated_at":"2025-04-05T03:10:34.748Z","avatar_url":"https://github.com/aalfiann.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e This is a fork version of [cachegoose](https://github.com/boblauer/cachegoose) with following differences :\n- Minimum NodeJS 16\n- Removed old libraries\n- Fixing all vulnerables\n- Up to date\n- Typescript [support](https://github.com/xrip/cachegoose)\n- Replace [cacheman](https://github.com/cayasso/cacheman) with [recacheman](https://github.com/aalfiann/recacheman)\n\n# recachegoose #\n\n#### Mongoose caching that actually works. ####\n\n[![NPM](https://nodei.co/npm/recachegoose.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://nodei.co/npm/recachegoose/)  \n  \n[![npm version](https://img.shields.io/npm/v/recachegoose.svg?style=flat-square)](https://www.npmjs.org/package/recachegoose)\n[![CircleCI](https://dl.circleci.com/status-badge/img/gh/aalfiann/recachegoose/tree/master.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/aalfiann/recachegoose/tree/master)\n[![Coverage Status](https://coveralls.io/repos/github/aalfiann/recachegoose/badge.svg?branch=master)](https://coveralls.io/github/aalfiann/recachegoose?branch=master)\n[![Known Vulnerabilities](https://snyk.io//test/github/aalfiann/recachegoose/badge.svg?targetFile=package.json)](https://snyk.io//test/github/aalfiann/recachegoose?targetFile=package.json)\n![License](https://img.shields.io/npm/l/recachegoose)\n![NPM download/month](https://img.shields.io/npm/dm/recachegoose.svg)\n![NPM download total](https://img.shields.io/npm/dt/recachegoose.svg)  \n\n## About ##\n\nA Mongoose caching module that works exactly how you would expect it to, with the latest version of Mongoose.\n\n\u003e Important:  \n  If you are using Mongoose 4.x or below, you have to use original [cachegoose](https://github.com/boblauer/cachegoose) and use version \u003c= 4.x of it.\n\n\n\n## Usage ##\n\n- Use In Memory\n```javascript\nvar mongoose = require('mongoose');\nvar cachegoose = require('recachegoose');\n\ncachegoose(mongoose, {\n  engine: 'memory'\n});\n```\n\n- Use File\n```javascript\nvar mongoose = require('mongoose');\nvar cachegoose = require('recachegoose');\n\ncachegoose(mongoose, {\n  engine: 'file'\n});\n```\n\n- Use Redis\n```javascript\nvar mongoose = require('mongoose');\nvar cachegoose = require('recachegoose');\n\ncachegoose(mongoose, {\n  engine: 'redis',\n  port: 6379,\n  host: 'localhost'\n});\n\n// or with redis url connection string\n// redis[s]://[[username][:password]@][host][:port][/db-number]\ncachegoose(mongoose, {\n  engine: 'redis',\n  url: 'redis://localhost:6379'\n});\n\n// or with redis client with connection string\n// backwards compatibility\ncachegoose(mongoose, {\n  engine: 'redis',\n  client: 'redis://localhost:6379'\n});\n\n// backwards compatibility\ncachegoose(mongoose, {\n  engine: 'redis',\n  client: require('redis').createClient('redis://localhost:6379')\n});\n```\n\n- Set Cache\n```js\nRecord\n  .find({ some_condition: true })\n  .cache(30) // The number of seconds to cache the query.  Defaults to 60 seconds.\n  .exec(function(err, records) { // You are able to use callback or promise\n    ...\n  });\n\nRecord\n  .aggregate()\n  .group({ total: { $sum: '$some_field' } })\n  .cache(0) // Explicitly passing in 0 will cache the results indefinitely.\n  .exec(function(err, aggResults) {\n    ...\n  });\n```\n\nYou can also pass a custom key into the `.cache()` method, which you can then use later to clear the cached content.\n\n```javascript\nvar userId = '1234567890';\n\nChildren\n  .find({ parentId: userId })\n  .cache(0, userId + '-children') /* Will create a redis entry          */\n  .exec(function(err, records) {  /* with the key '1234567890-children' */\n    ...\n  });\n\nChildrenSchema.post('save', function(child) {\n  // Clear the parent's cache, since a new child has been added.\n  cachegoose.clearCache(child.parentId + '-children');\n});\n```\n\nInsert `.cache()` into the queries you want to cache, and they will be cached.  Works with `select`, `lean`, `sort`, and anything else that will modify the results of a query.\n\n## Clearing the cache ##\n\nIf you want to clear the cache for a specific query, you must specify the cache key yourself:\n\n```js\nfunction getChildrenByParentId(parentId, cb) {\n  Children\n    .find({ parentId })\n    .cache(0, `${parentId}_children`)\n    .exec(cb);\n}\n\nfunction clearChildrenByParentIdCache(parentId, cb) {\n  cachegoose.clearCache(`${parentId}_children`, cb);\n}\n```\n\nIf you call `cachegoose.clearCache(null, cb)` without passing a cache key as the first parameter, the entire cache will be cleared for all queries.\n\n## Caching populated documents ##\n\nWhen a document is returned from the cache, cachegoose will [hydrate](http://mongoosejs.com/docs/api.html#model_Model.hydrate) it, which initializes it's virtuals/methods. Hydrating a populated document will discard any populated fields (see [Automattic/mongoose#4727](https://github.com/Automattic/mongoose/issues/4727)). To cache populated documents without losing child documents, you must use `.lean()`, however if you do this you will not be able to use any virtuals/methods (it will be a plain object).\n\n## Test ##\nFor development mode, you have to use minimum nodejs 14\n```\nnpm test\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faalfiann%2Frecachegoose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faalfiann%2Frecachegoose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faalfiann%2Frecachegoose/lists"}