Skip to content

Commit

Permalink
Updating LRU cache, removing notification functionality (wrong place …
Browse files Browse the repository at this point in the history
…to attempt this)
  • Loading branch information
avoidwork committed Dec 9, 2018
1 parent 7fa104e commit 4339089
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ http.createServer(router.route).listen(8000);

## API

##### etag ({cacheSize: 1000, cacheTTL: 0, seed: random, notify: false, onchange: (eventName, serializedCache) => {}, mimetype: "text/plain"})
Returns an tiny-etag instance. Be notified of cache changes by setting `notify` to `true`, and supply `onchange`. Cache TTL concerns do not spread with a notification.
##### etag ({cacheSize: 1000, cacheTTL: 0, seed: random, mimetype: "text/plain"})
Returns an tiny-etag instance. Cache TTL concerns do not spread with a notification.

##### create (arg)
Creates a strong ETag value from `arg`
Expand Down
5 changes: 2 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
const path = require("path"),
ETag = require(path.join(__dirname, "lib", "etag.js"));

function factory ({cacheSize = 1e3, cacheTTL = 0, seed = null, notify = false, onchange = () => {}, mimetype = "text/plain"} = {}) {
const obj = new ETag(cacheSize, cacheTTL, seed !== null ? seed : Math.floor(Math.random() * cacheSize) + 1, notify, mimetype);
function factory ({cacheSize = 1e3, cacheTTL = 0, seed = null, mimetype = "text/plain"} = {}) {
const obj = new ETag(cacheSize, cacheTTL, seed !== null ? seed : Math.floor(Math.random() * cacheSize) + 1, mimetype);

obj.middleware = obj.middleware.bind(obj);
obj.cache.onchange = onchange;

return obj;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/etag.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ function parse (arg) {
}

class ETag {
constructor (cacheSize, cacheTTL, seed, notify, mimetype) {
this.cache = lru(cacheSize, notify, cacheTTL);
constructor (cacheSize, cacheTTL, seed, mimetype) {
this.cache = lru(cacheSize, cacheTTL);
this.mimetype = mimetype;
this.seed = seed;
}
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tiny-etag",
"version": "1.5.16",
"version": "2.0.0",
"description": "ETag middleware",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -29,14 +29,14 @@
"homepage": "http://avoidwork.github.io/tiny-etag/",
"dependencies": {
"murmurhash3js": "^3.0.1",
"tiny-lru": "^4.0.6"
"tiny-lru": "^5.0.0"
},
"devDependencies": {
"grunt": "^1.0.3",
"grunt-eslint": "^21.0.0",
"grunt-mocha-test": "^0.13.3",
"mocha": "^5.2.0",
"tiny-httptest": "^1.0.22",
"woodland": "^7.3.19"
"woodland": "^7.3.20"
}
}

0 comments on commit 4339089

Please sign in to comment.