A module for caching static http responses in memory. It's available through npm
npm install cashier
Cashier allows you to cache in memory a result from a function and serve it using http.
It does so by wrapping a function into connect compatible middleware.
var cashier = ;var fs = ;var serveFiles =;// let's mount it using expressvar express = ;var app = ;app;app;
If you save the above example as
example.js and afterwards run it and visit
http://localhost:8080/example.js you should see the file being served.
Cashier is ensuring that we actually only read the file from disk once - any subsequent requests will be served from the cache.
Since we pass the
watch option Cashier will clear the cache if any of the files in the array changes.
Cashier will also normalize all urls before they are parsed to your function.
This means you do not need to worry about
../../ attacks in your urls.
dataa buffer or a string to be responded (a gzipped version will also be saved)
watcha file or array of files to be watched - the cache will clear if they are modified.
typethe content-type of the response
(The MIT License)
Copyright (c) 2012 Mathias Buus Madsen <email@example.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.