Change module name json_cache to JSONCache, get() to open(), set() to flush()
authorNick Downing <downing.nick@gmail.com>
Sat, 20 Oct 2018 03:51:43 +0000 (14:51 +1100)
committerNick Downing <downing.nick@gmail.com>
Sat, 20 Oct 2018 03:51:43 +0000 (14:51 +1100)
.gitignore
JSONCache.js [moved from json_cache.js with 93% similarity]
package.json

index 3633f2f..21f41bb 100644 (file)
@@ -1 +1 @@
-/json_cache-*.tgz
+/JSONCache-*.tgz
similarity index 93%
rename from json_cache.js
rename to JSONCache.js
index 563bc8e..0b5976e 100644 (file)
@@ -4,11 +4,11 @@ let util = require('util')
 let fs_readFile = util.promisify(fs.readFile)
 let fs_writeFile = util.promisify(fs.writeFile)
 
-let JSONCache = function() {
+let JSONCache = function(diag) {
   if (!this instanceof JSONCache)
     throw Error('JSONCache is a constructor')
   this.map = new Map()
-  this.diag = false
+  this.diag = diag || false
 }
 
 let load = (diag, key, default_value) => {
@@ -32,7 +32,7 @@ let load = (diag, key, default_value) => {
   return result
 }
 
-JSONCache.prototype.get = async function(key, default_value) {
+JSONCache.prototype.open = async function(key, default_value) {
   let result = this.map.get(key)
   if (result === undefined) {
     result = load(this.diag, key, default_value)
@@ -67,7 +67,7 @@ let save = (diag, key, result, timeout) => {
   }
 }
 
-JSONCache.prototype.set = async function(key, value, timeout) {
+JSONCache.prototype.flush = async function(key, value, timeout) {
   let result = this.map.get(key)
   if (result === undefined) {
     assert(value !== undefined)
index b19a575..920962c 100644 (file)
@@ -1,8 +1,8 @@
 {
-  "name": "json_cache",
+  "name": "JSONCache",
   "version": "1.0.0",
   "description": "Simple caching scheme with atomic modification and delayed write",
-  "main": "json_cache.js",
+  "main": "JSONCache.js",
   "directories": {},
   "dependencies": {
     "fs": "^0.0.1-security"