{"id":18389763,"url":"https://github.com/danielwpz/cacheasy","last_synced_at":"2025-04-12T06:30:12.435Z","repository":{"id":42983222,"uuid":"208001518","full_name":"danielwpz/cacheasy","owner":"danielwpz","description":"Cache library for nodejs","archived":false,"fork":false,"pushed_at":"2022-03-24T20:09:00.000Z","size":89,"stargazers_count":1,"open_issues_count":6,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-16T01:13:33.758Z","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/danielwpz.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":"2019-09-12T08:28:18.000Z","updated_at":"2020-12-21T04:41:03.000Z","dependencies_parsed_at":"2022-09-19T18:50:36.628Z","dependency_job_id":null,"html_url":"https://github.com/danielwpz/cacheasy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielwpz%2Fcacheasy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielwpz%2Fcacheasy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielwpz%2Fcacheasy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielwpz%2Fcacheasy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielwpz","download_url":"https://codeload.github.com/danielwpz/cacheasy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248528986,"owners_count":21119415,"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-11-06T01:44:27.400Z","updated_at":"2025-04-12T06:30:12.371Z","avatar_url":"https://github.com/danielwpz.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cacheasy\nMulti-backend cache library for nodejs\n\n## API\n1. `CacheStore`       \n    - `new CacheStore(store)`\n      Create a new cache store with given backend.\n\n    - `CacheStore.cache(key, generator, options)`     \n      Get the cached value for key. If cache missed, generator will be run and the returned value will be cached.      \n      generator could either be a `async function` which returns a value, or a value it self.      \n      `options.ttl`: TTL\n\n    - `CacheStore.set(key, generator, options)`      \n      Simple set the key with generator.        \n      `options.ttl`: TTL\n\n    - `CacheStore.get(key)`      \n      Get cached value for key.\n\n2. `MemoryCacheStore`\n    - `new MemoryCacheStore()`      \n      Create new memory based cache store.\n\n3. `RedisCacheStore`      \n    - `new RedisCacheStore(redisOptions)`     \n      Create new redis based cache store.\n      options: [ioredis](https://github.com/luin/ioredis/blob/master/API.md) options\n\n## Example\n```javascript\nconst Cacheasy = require('../index')\nconst { RedisCacheStore } = Cacheasy.store\nconst assert = require('assert')\n\nconst redisStore = new RedisCacheStore()\nconst cache = new Cacheasy(redisStore)\n\nasync function test () {\n  return cache.cache('foo', async () =\u003e 'bar')\n}\n\nasync function fail () {\n  return cache.cache('boom', () =\u003e {\n    throw new Error('something happened')\n  })\n}\n\ntest()\n  .then(test)  // cache hit for this time\n  .then(value =\u003e assert(value === 'bar'))\n  .then(fail)  // exceptions will not be cached\n  .catch(err =\u003e {\n    assert(err.message === 'something happened')\n  })\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielwpz%2Fcacheasy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielwpz%2Fcacheasy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielwpz%2Fcacheasy/lists"}