{"id":17046551,"url":"https://github.com/calintamas/react-native-cachemere","last_synced_at":"2025-04-12T15:32:50.231Z","repository":{"id":40796450,"uuid":"200474356","full_name":"calintamas/react-native-cachemere","owner":"calintamas","description":"Async cache manager","archived":false,"fork":false,"pushed_at":"2023-03-04T04:55:22.000Z","size":677,"stargazers_count":4,"open_issues_count":11,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T10:04:13.611Z","etag":null,"topics":["cache","react-native","storage"],"latest_commit_sha":null,"homepage":"","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/calintamas.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":"2019-08-04T09:34:53.000Z","updated_at":"2023-03-14T23:10:13.000Z","dependencies_parsed_at":"2023-02-05T02:31:17.668Z","dependency_job_id":null,"html_url":"https://github.com/calintamas/react-native-cachemere","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calintamas%2Freact-native-cachemere","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calintamas%2Freact-native-cachemere/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calintamas%2Freact-native-cachemere/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calintamas%2Freact-native-cachemere/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/calintamas","download_url":"https://codeload.github.com/calintamas/react-native-cachemere/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248589856,"owners_count":21129690,"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","react-native","storage"],"created_at":"2024-10-14T09:46:41.432Z","updated_at":"2025-04-12T15:32:50.204Z","avatar_url":"https://github.com/calintamas.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-native-cachemere\n![npm version](https://img.shields.io/npm/v/react-native-cachemere)\n![npm downloads](https://img.shields.io/npm/dt/react-native-cachemere)\n\nAn async cache manager.\n\n## Install\nSince `AsyncStorage` has been removed from the React Native core, you first need to install [@react-native-community/async-storage](https://github.com/react-native-community/async-storage). Then,\n```\nyarn add react-native-cachemere\n```\n\n## Example\n```js\nimport Cache from 'react-native-cachemere'\n\nconst getData = async () =\u003e {\n  const CACHE_KEY = `my_cache_key`;\n\n  // First, try to get data from cache\n  const cachedData = await Cache.get(CACHE_KEY);\n  if (cachedData) {\n    return cachedData\n  }\n\n  // If no cache is set, get data from server\n  const data = await getDataFromServer();\n\n  // Then, cache that data  \n  const INVALIDATE_AFTER = 3; // the number of attempts after which the cache is invalidated\n                              // if set to null, cache is only invalidated after TTL expires\n\n  const TTL = Cache.TTL_12H;  // cache for 12h\n  await Cache.set(CACHE_KEY, data, TTL, INVALIDATE_AFTER);\n\n  return data\n}\n```\n\n## Usage\n### set\n```js\nawait Cache.set(key, data, ttl, attempts)\n```\n`key` is a string used to set and get the cached data.\n\n`data` must be serializable object.\n\n`ttl` is expressed in seconds. There are some standard TTLs exposed by the lib.\n```js\nCache.TTL_12H = 43200\nCache.TTL_8H = 28800\nCache.TTL_6H = 21600\nCache.TTL_4H = 14400\nCache.TTL_1H = 3600\n```\n\n`attempts` is an integer. Cache is invalidated after this number of attempts. If left unset (or set to `null`), cache is only invalidated after TTL expires.\n\n### get\n```js\nawait Cache.get(key)\n```\nReturns the data as a parsed JSON. If there's no cached data for that `key` or that data cache has expired, returns `null`.\n\n\u003e When cache expires it is automatically cleared from the storage.\n\n### getAll\n```js\nconst all = await Cache.getAll()\n```\nReturns an array with all cached objects, parsed.\n\n### clear\n```js\nawait Cache.clear(key)\n```\nCache is removed for the specified `key`.\n\n### clearExpired\n```js\nawait Cache.clearExpired()\n```\nRemove all expired cache. Can be called at app startup to ensure a decluttered Storage.\n\n### clearByRegex\n```js\nawait Cache.clearByRegex(regex)\n```\nRemove all cache with keys that pass the `regex` condition. \nCan be used when fetching the data with pagination and need to cache every group of data received.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcalintamas%2Freact-native-cachemere","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcalintamas%2Freact-native-cachemere","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcalintamas%2Freact-native-cachemere/lists"}