Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

koa-static-cache

Package Overview
Dependencies
Maintainers
9
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-static-cache - npm Package Compare versions

Comparing version 4.0.0 to 4.1.0

5

HISTORY.md
4.1.0 / 2017-06-01
==================
* feat: files support lru (#64)
4.0.0 / 2017-02-21

@@ -3,0 +8,0 @@ ==================

30

index.js

@@ -20,3 +20,3 @@ var crypto = require('crypto')

options.prefix = (options.prefix || '').replace(/\/*$/, '/')
files = files || options.files || Object.create(null)
files = new FileManager(files || options.files)
dir = dir || options.dir || process.cwd()

@@ -41,4 +41,4 @@ var enableGzip = !!options.gzip

if (files[value]) {
files[key] = files[value]
if (files.get(value)) {
files.set(key, files.get(value))

@@ -60,3 +60,3 @@ debug('aliasing ' + value + ' as ' + key)

var file = files[filename]
var file = files.get(filename)

@@ -133,3 +133,3 @@ // try to load file

var gzFile = files[filename + '.gz']
var gzFile = files.get(filename + '.gz')
if (options.usePrecompiledGzip && gzFile && gzFile.buffer) { // if .gz file already read from disk

@@ -190,3 +190,4 @@ file.zipBuffer = gzFile.buffer

var pathname = path.normalize(path.join(options.prefix, name))
var obj = files[pathname] = files[pathname] ? files[pathname] : {}
if (!files.get(pathname)) files.set(pathname, {})
var obj = files.get(pathname)
var filename = obj.path = path.join(dir, name)

@@ -210,1 +211,18 @@ var stats = fs.statSync(filename)

}
function FileManager(store) {
if (store && typeof store.set === 'function' && typeof store.get === 'function') {
this.store = store
} else {
this.map = store || Object.create(null)
}
}
FileManager.prototype.get = function (key) {
return this.store ? this.store.get(key) : this.map[key]
}
FileManager.prototype.set = function (key, value) {
if (this.store) return this.store.set(key, value)
this.map[key] = value
}
{
"name": "koa-static-cache",
"description": "Static cache for koa",
"version": "4.0.0",
"version": "4.1.0",
"author": {

@@ -60,3 +60,4 @@ "name": "Jonathan Ong",

"should-http": "0.0.4",
"supertest": "1"
"supertest": "1",
"ylru": "1"
},

@@ -63,0 +64,0 @@ "scripts": {

20

README.md

@@ -55,6 +55,7 @@ # Koa Static Cache

- `options.prefix` (str) - the url prefix you wish to add, default to `''`.
- `files` (obj) - optional files object. See below.
- `options.dynamic` (bool) - dynamic load file which not cached on initialization.
- `options.filter` (function | array) - filter files at init dir, for example - skip non build (source) files. If array set - allow only listed files
- `options.preload` (bool) - caches the assets on initialization or not, default to `true`. always work togather with `options.dynamic`.
- `options.preload` (bool) - caches the assets on initialization or not, default to `true`. always work together with `options.dynamic`.
- `options.files` (obj) - optional files object. See below.
- `files` (obj) - optional files object. See below.

@@ -116,2 +117,17 @@ ### Aliases

#### Using a LRU cache to avoid OOM when dynamic mode enabled
You can pass in a lru cache instance which has tow methods: `get(key)` and `set(key, value)`.
```js
var LRU = require('lru-cache')
var files = new LRU({ max: 1000 })
app.use(staticCache({
dir: '/public',
dynamic: true,
files: files
}))
```
## License

@@ -118,0 +134,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc