{"id":18429447,"url":"https://github.com/bigpipe/hotpath","last_synced_at":"2025-04-13T21:44:41.304Z","repository":{"id":25272208,"uuid":"28697729","full_name":"bigpipe/hotpath","owner":"bigpipe","description":"Memory restricted hot path cache","archived":false,"fork":false,"pushed_at":"2020-10-26T13:13:32.000Z","size":12,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-02-16T08:43:10.045Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bigpipe.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":"2015-01-01T22:51:31.000Z","updated_at":"2020-10-26T13:13:34.000Z","dependencies_parsed_at":"2022-08-25T03:41:00.095Z","dependency_job_id":null,"html_url":"https://github.com/bigpipe/hotpath","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigpipe%2Fhotpath","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigpipe%2Fhotpath/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigpipe%2Fhotpath/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigpipe%2Fhotpath/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bigpipe","download_url":"https://codeload.github.com/bigpipe/hotpath/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248788869,"owners_count":21161726,"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-06T05:17:11.182Z","updated_at":"2025-04-13T21:44:41.282Z","avatar_url":"https://github.com/bigpipe.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hotpath\n\n[![Version npm][version]](http://browsenpm.org/package/hotpath)[![Build Status][build]](https://travis-ci.org/bigpipe/hotpath)[![Dependencies][david]](https://david-dm.org/bigpipe/hotpath)[![Coverage Status][cover]](https://coveralls.io/r/bigpipe/hotpath?branch=master)\n\n[from]: https://img.shields.io/badge/from-bigpipe.io-9d8dff.svg?style=flat-square\n[version]: http://img.shields.io/npm/v/hotpath.svg?style=flat-square\n[build]: http://img.shields.io/travis/bigpipe/hotpath/master.svg?style=flat-square\n[david]: https://img.shields.io/david/bigpipe/hotpath.svg?style=flat-square\n[cover]: http://img.shields.io/coveralls/bigpipe/hotpath/master.svg?style=flat-square\n\nHotpath is memory restricted cache layer. It's intended use is to cache the most\ncritical code or data of your application without using to much memory.\nOptimizations for the sake of performance are great as long as they do not\naffect the memory management of your process.\n\n#### Our use case:\n\nSevering files directly out of node's memory minimizes the about of I/O we need\nto serve the given file. The restricted hot path cache ensures that only the top\nrequested files get cached and we do not blow out of memory. It only takes\na small percentage of free memory. 2% by default and 10% if you have more than\n1.7 GB available on your system.\n\n## Installation\n\nThe module is released frequently to the npm registry and can be installed\nusing:\n\n```\nnpm install --save hotpath\n```\n\n## Usage\n\nIn all code example we assume that the library has been required as following:\n\n```js\n'use strict';\n\nvar HotPath = require('hotpath');\n```\n\nTo create a new hot path cache you need to construct a new instance:\n\n```js\nvar hotpath = new HotPath({ option });\n```\n\nTo customize your `HotPath` instance you can supply the following options in the\nconstructor: \n\n- `maximum`: The maximum amount of memory we can allocate for our given cache.\n  Defaults to `1.7 gb` the value is parsed with the [bytes] module.\n- `available`: The amount of memory available on the system. We will calculate\n  our cache size based on this. It should be given as bytes. Defaults to the\n  `os.freemem()` result.\n- `prefix`: A prefix for the keys to prevent dictionary attacks when storing\n  things like `__proto__` in the object. Defaults to `_HotPath`\n- `countkey`: Include the size of they in the allocated memory count. Defaults\n  to `false`.\n\n#### hotpath.set\n\nTo add items to your cache you need to call the `set` method with 2 argument:\n\n1. `key`: name where your data is stored under.\n2. `data`: value that needs to be stored. \n\nIf the supplied `data` is not an `Buffer` we will automatically transform it in\nto a new buffer for you. So when you retrieve your data from the cache again it\nwill always be a `Buffer` instance.\n\n```js\nvar stored = hotpath.set('my-custom-key', new Buffer('\u003cmy important blob of data\u003e'));\n```\n\nIf you item is successfully stored in the cache it will return `true` as\nboolean. The only reason why you would get a `false` boolean is when the data\nyou want to store is larger than the available size.\n\n#### hotpath.allocated\n\nThe `.allocated` property allows you to check how many bytes are currently stored\nin your cache. To see how much data you can still store you can subtract it from\nthe `.free` property.\n\n```js\nconsole.log('in-use', hotpath.allocated);\nconsole.log('available', hotpath.free - hotpath.allocated);\n```\n\n#### hotpath.get\n\nRetrieve the value that is stored in the cache. Please note that any\nmodification you do on this buffer will also be changed in the cache as this is\n**NOT** a copy. The get method accepts one argument:\n\n1. `key`: name where your data is stored under.\n\n```js\nvar value = hotpath.get('my-custom-key');\n```\n\n#### hotpath.remove\n\nTo remove individual values from the cache you can use the remove method. It\ntakes one argument:\n\n1. `key`: name where your data is stored under.\n\n```js\nvar removed = hotpath.remove('my-custom-key');\n```\n\nThe remove method returns a boolean indicating if the removal was successful.\nWhen you receive `false` we could not locate the item in the cache.\n\n#### hotpath.reset\n\nIf you want to reset the complete cache instead of removing just a single\nindividual value you should call the reset method. It creates a fresh new object\nwhere all data is stored in and reset the `allocated` property.\n\n```js\nhotpath.reset();\n```\n\n#### hotpath.destroy\n\nIf you no longer which to use or reference your hot path cache you should\ndestroy it completely in order to release the saved memory again. Only call this\nmethod if you will no longer reference any of it's methods as all the internal\nstructure will be nuked to death.\n\n```js\nhotpath.destroy();\n```\n\n## License\n\nMIT\n\n[bytes]: http://npm.im/bytes\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigpipe%2Fhotpath","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbigpipe%2Fhotpath","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigpipe%2Fhotpath/lists"}