{"id":17988858,"url":"https://github.com/yashkumarverma/easy-cache","last_synced_at":"2025-03-25T23:30:32.072Z","repository":{"id":57110427,"uuid":"391705499","full_name":"YashKumarVerma/easy-cache","owner":"YashKumarVerma","description":"a NPM module to cache any given function / class using a single line.","archived":false,"fork":false,"pushed_at":"2021-08-10T03:11:29.000Z","size":275,"stargazers_count":14,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-17T22:23:00.926Z","etag":null,"topics":["cache","easy-cache","npm","package","redis"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@easy-cache/core","language":"TypeScript","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/YashKumarVerma.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}},"created_at":"2021-08-01T18:22:08.000Z","updated_at":"2023-10-21T14:26:53.000Z","dependencies_parsed_at":"2022-08-21T09:00:38.161Z","dependency_job_id":null,"html_url":"https://github.com/YashKumarVerma/easy-cache","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/YashKumarVerma%2Feasy-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YashKumarVerma%2Feasy-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YashKumarVerma%2Feasy-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YashKumarVerma%2Feasy-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YashKumarVerma","download_url":"https://codeload.github.com/YashKumarVerma/easy-cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245560973,"owners_count":20635657,"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":["cache","easy-cache","npm","package","redis"],"created_at":"2024-10-29T19:12:57.758Z","updated_at":"2025-03-25T23:30:31.706Z","avatar_url":"https://github.com/YashKumarVerma.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e A modern NodeJS package to cache any function with just a **single line of code** - @easy-cache\n\n![EasyCache](https://github.com/YashKumarVerma/easy-cache/blob/master/assets/banner.png?raw=true)\n\n[![Ensure Package Builds](https://github.com/YashKumarVerma/easy-cache/actions/workflows/build.yml/badge.svg)](https://github.com/YashKumarVerma/easy-cache/actions/workflows/build.yml)\n[![Tests](https://github.com/YashKumarVerma/easy-cache/actions/workflows/test.yml/badge.svg)](https://github.com/YashKumarVerma/easy-cache/actions/workflows/test.yml)\n\n# EasyCache\n\n## 🤔 What is EasyCache v1.0?\n\n@easy-cache is a NodeJS module available on NPM to cache any function with just a single line of code. It helps you to boost your application in the cleanest way possible. Allows setting global as well as local cache options. Supports TypeScript as well as JavaScript.\n\nPrimary features of @easy-cache are:\n\n- Global configuration options to configure entire application at one place.\n- Local configuration option to configure any function as required, overriding the global configs.\n- Custom TTL (Time to Live) to customize cache invalidation.\n- Built in support for Redis as cache server. (_Others coming in v2.0_)\n- Support for javaScript and TypeScript in a single package.\n- Single line implementation even in JS where decorators do not exist.\n- brutally tested and production ready.\n\n# Usage\n\nThe package can be directly used in any nodejs (TypeScript / JavaScript) based backend.\n\n**Step 1**: Install the package\n\n```\nnpm install @easy-cache/core\n\n# or\n\nyarn add @easy-cache/core\n```\n\n\u003e Note: In v1.0, the default cache engine i.e. `redis` is used, and therefore the `redis` package is also installed by default. From v2.0 onwards, there would be 0 dependencies in the core package.\n\n**Step 2**: Initialize the cache system\n\n```javascript\n/** Initializing the cache system */\nimport EasyCache from '@easy-cache/core'\n\nconst cacheInstance = new EasyCache({\n  // TTL Value in seconds\n  defaultTTL: 10,\n\n  // redis connection details\n  redisHost: '127.0.0.1',\n  redisPassword: '',\n  redisPort: 6379,\n\n  // whether to show verbose logs\n  debug: false,\n\n  // completely disable the cache globally\n  disable: false,\n})\n\n/** the function that you want to cache **/\nfunction fullName(fistName, lastName) {\n  return `${firstName} ${lastName}`\n}\n\n/** To cache the function, just pass it into the provider with configs..\n *\n * Configurations can be passed into the provider to change the behavior.\n * disable: to turn of cache for given funtion\n * expireAfter: to set a custom expire time for given function\n * debug: to show verbose logs for given function\n */\nconst cachedFullName = cacheInstance.provider({ debug: true }, fullName)\n```\n\n### Using with classes\n\nSince v1.0, EasyCache supports classes as well, using a unique method called decorators.\nSimply adding `@EasyCache.Cache({configs})` will cache the following function.\n\n**Example**:\n\n```ts\nclass MyClass {\n  @EasyCacheInstance.Cache({ defaultTTL: 30 })\n  public static thisMethodWillBeCached() {\n    // some code\n    return true\n  }\n}\n```\n\nThe above function would cache with a ttl of 30 seconds.\n\n# Tests\n\nTests are a vital component of any software project. In @easy-cache,\n\n- the unit tests are written in TypeScript using Mocha and Chai.\n- the end to end tests are being written in JavaScript using Mocha and Chai.\n\nA detailed analysis about the above is [posted here](https://medium.com/@yk.verma2000/tdd-design-choices-src-or-dist-7261c7c81cb0).\n\n# Roadmap\n\n### Version 1\n\n- @cache decorator to implement caching for class methods.\n- provider to cache orphan functions (without decorators).\n- Support for javascript and typescript.\n- Redis as a default provider for caching.\n- Robust test suite.\n\n### Version 2\n\n- Support for plugins to add any generic provider.\n- Support for Postgres, Memcached, etc. as providers on rolling basis.\n- Plugins\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyashkumarverma%2Feasy-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyashkumarverma%2Feasy-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyashkumarverma%2Feasy-cache/lists"}