From bfaf65023e3553df7a59c3e5e19c40276ae3afa1 Mon Sep 17 00:00:00 2001 From: Nick Downing Date: Tue, 20 Nov 2018 12:22:51 +1100 Subject: [PATCH 1/1] Initial commit --- .gitignore | 5 +++++ LICENSE | 20 +++++++++++++++++++ ZettairCache.js | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 32 ++++++++++++++++++++++++++++++ 4 files changed, 109 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 ZettairCache.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..427c101 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/ndcode-emailjs_cache-*.tgz +/node_modules +/package-lock.json +/yarn.lock +/yarn-error.log diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..aa360c1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +Copyright (C) 2018 Nick Downing +SPDX-License-Identifier: MIT + +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. diff --git a/ZettairCache.js b/ZettairCache.js new file mode 100644 index 0000000..d7560d3 --- /dev/null +++ b/ZettairCache.js @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2018 Nick Downing + * SPDX-License-Identifier: MIT + * + * 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. + */ + +let BuildCache = require('@ndcode/build_cache') +let zettair = require('@ndcode/zettair') + +let ZettairCache = function(diag) { + if (!this instanceof ZettairCache) + throw Error('ZettairCache is a constructor') + this.diag = diag || false + + this.build_cache = new BuildCache() +} + +ZettairCache.prototype.get = function(key) { + return /*await*/ this.build_cache.get( + key, + async result => { + result.deps = [ + `${key}.map.0`, + `${key}.param.0`, + `${key}.v.0`, + `${key}.vocab.0` + ] + result.value = new zettair.Index(key) + if (this.diag) + console.log(`opened zettair index ${key}`) + } + ) +} + +module.exports = ZettairCache diff --git a/package.json b/package.json new file mode 100644 index 0000000..fc1d776 --- /dev/null +++ b/package.json @@ -0,0 +1,32 @@ +{ + "name": "@ndcode/zettair_cache", + "version": "0.1.0", + "description": "Load zettair index which can be changed while system is live.", + "keywords": [ + "zettair", + "index", + "persistent", + "cache", + "live" + ], + "homepage": "https://www.ndcode.org", + "repository": { + "type": "git", + "url": "https://git.ndcode.org/public/zettair_cache.git" + }, + "bugs": { + "email": "nick@ndcode.org" + }, + "main": "ZettairCache.js", + "engines": { + "node": ">=0.4.0" + }, + "directories": {}, + "dependencies": { + "@ndcode/build_cache": "^0.1.0", + "@ndcode/zettair": "^0.1.3" + }, + "devDependencies": {}, + "maintainers": "Nick Downing ", + "license": "MIT" +} -- 2.34.1