{"id":13547558,"url":"https://github.com/avoidwork/tiny-lru","last_synced_at":"2025-05-14T18:07:22.805Z","repository":{"id":528989,"uuid":"11684125","full_name":"avoidwork/tiny-lru","owner":"avoidwork","description":"Tiny LRU cache for Client or Server","archived":false,"fork":false,"pushed_at":"2025-05-02T06:38:41.000Z","size":1831,"stargazers_count":162,"open_issues_count":0,"forks_count":25,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-02T07:43:54.860Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/avoidwork.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","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,"zenodo":null},"funding":{"github":["avoidwork"]}},"created_at":"2013-07-26T11:14:15.000Z","updated_at":"2025-05-02T06:38:44.000Z","dependencies_parsed_at":"2023-07-05T15:03:33.334Z","dependency_job_id":"75d5ba6d-0531-45e0-a1cd-64dc32613b7e","html_url":"https://github.com/avoidwork/tiny-lru","commit_stats":{"total_commits":476,"total_committers":15,"mean_commits":"31.733333333333334","dds":0.4642857142857143,"last_synced_commit":"45012f35aec9b2811c8eda59f418aff3226cfac6"},"previous_names":[],"tags_count":103,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avoidwork%2Ftiny-lru","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avoidwork%2Ftiny-lru/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avoidwork%2Ftiny-lru/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avoidwork%2Ftiny-lru/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/avoidwork","download_url":"https://codeload.github.com/avoidwork/tiny-lru/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254198515,"owners_count":22030966,"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-08-01T12:00:58.007Z","updated_at":"2025-05-14T18:07:17.797Z","avatar_url":"https://github.com/avoidwork.png","language":"JavaScript","readme":"# Tiny LRU\n\nLeast Recently Used cache for Client or Server.\n\n## Using the factory\n\n```javascript\nimport {lru} from \"tiny-lru\";\nconst cache = lru(max, ttl = 0, resetTtl = false);\n```\n\n## Using the Class\n\n```javascript\nimport {LRU} from \"tiny-lru\";\nconst cache = new LRU(max, ttl = 0, resetTtl = false);\n```\n\n```javascript\nimport {LRU} from \"tiny-lru\";\nclass MyCache extends LRU {}\n```\n\n## Interoperability\n\nLodash provides a `memoize` function with a cache that can be swapped out as long as it implements the right interface.\nSee the [lodash docs](https://lodash.com/docs#memoize) for more on `memoize`.\n\n### Example\n```javascript\n_.memoize.Cache = lru().constructor;\nconst memoized = _.memoize(myFunc);\nmemoized.cache.max = 10;\n```\n\n## Testing\n\nTiny-LRU has 100% code coverage with its tests.\n\n```console\n--------------|---------|----------|---------|---------|-------------------\nFile          | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s\n--------------|---------|----------|---------|---------|-------------------\nAll files     |     100 |    91.54 |     100 |     100 |\n tiny-lru.cjs |     100 |    91.54 |     100 |     100 | 11-31,150,184\n--------------|---------|----------|---------|---------|-------------------\n```\n\n## API\n\n## Properties\n\n### first\n\nItem in \"first\" or \"bottom\" position; default is `null`\n\n**Example**\n\n```javascript\nconst cache = lru();\n\ncache.first; // null - it's a new cache!\n```\n\n### last\n\nItem in \"last\" or \"top\" position; default is `null`\n\n**Example**\n\n```javascript\nconst cache = lru();\n\ncache.last; // null - it's a new cache!\n```\n\n### max\n\nMax items to hold in cache; default is `1000`\n\n**Example**\n\n```javascript\nconst cache = lru(500);\n\ncache.max; // 500\n```\n\n### resetTtl\n\nResets `item.expiry` with each `set()` if `true`; default is `false`\n\n**Example**\n\n```javascript\nconst cache = lru(500, 5*6e4, true);\n\ncache.resetTtl; // true\n```\n\n### size\n\nNumber of items in cache\n\n**Example**\n\n```javascript\nconst cache = lru();\n\ncache.size; // 0 - it's a new cache!\n```\n\n### ttl\n\nMilliseconds an item will remain in cache; lazy expiration upon next `get()` of an item\n\n**Example**\n\n```javascript\nconst cache = lru(100, 3e4);\n\ncache.ttl; // 30000;\n```\n\n## Methods\n\n### clear\n\nClears the contents of the cache\n\n\treturn {Object} LRU instance\n\n**Example**\n\n```javascript\ncache.clear();\n```\n\n### delete\n\nRemoves item from cache\n\n\tparam  {String} key Item key\n\treturn {Object}     LRU instance\n\n**Example**\n\n```javascript\ncache.delete(\"myKey\");\n```\n\n### entries(*[\"key1\", \"key2\"]*)\n\nReturns an `Array` cache items\n\n    param  {Array} keys (Optional) Cache item keys to get, defaults to `this.keys()` if not provided\n\treturn {Object} LRU instance\n\n**Example**\n\n```javascript\ncache.entries(['myKey1', 'myKey2']);\n```\n\n### evict\n\nEvicts the least recently used item from cache\n\n\treturn {Object} LRU instance\n\n**Example**\n\n```javascript\ncache.evict();\n```\n\n### expiresAt\n\nGets expiration time for cached item\n\n\tparam  {String} key Item key\n\treturn {Mixed}      Undefined or number (epoch time)\n\n**Example**\n\n```javascript\nconst item = cache.expiresAt(\"myKey\");\n```\n\n### get\n\nGets cached item and moves it to the front\n\n\tparam  {String} key Item key\n\treturn {Mixed}      Undefined or Item value\n\n**Example**\n\n```javascript\nconst item = cache.get(\"myKey\");\n```\n\n### has\n\nReturns a `Boolean` indicating if `key` is in cache\n\n\treturn {Object} LRU instance\n\n**Example**\n\n```javascript\ncache.has('myKey');\n```\n\n### keys\n\nReturns an `Array` of cache item keys (`first` to `last`)\n\n\treturn {Array} Array of keys\n\n**Example**\n\n```javascript\nconsole.log(cache.keys());\n```\n\n### set\n\nSets item in cache as `first`\n\n\tparam  {String} key   Item key\n\tparam  {Mixed}  value Item value\n\treturn {Object}       LRU instance\n\n**Example**\n\n```javascript\ncache.set(\"myKey\", {prop: true});\n```\n\n### values(*[\"key1\", \"key2\"]*)\n\nReturns an `Array` cache items\n\n\tparam  {Array} keys (Optional) Cache item keys to get\n\treturn {Array} Cache items\n\n**Example**\n\n```javascript\ncache.values(['abc', 'def']);\n```\n\n## License\nCopyright (c) 2024 Jason Mulligan\nLicensed under the BSD-3 license.\n","funding_links":["https://github.com/sponsors/avoidwork"],"categories":["JavaScript","Packages"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favoidwork%2Ftiny-lru","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Favoidwork%2Ftiny-lru","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favoidwork%2Ftiny-lru/lists"}