aboutsummaryrefslogtreecommitdiff
path: root/node_modules/express-minify/cache.js
diff options
context:
space:
mode:
authorHumairAK <humair88@hotmail.com>2016-07-27 06:44:05 +0000
committerHumairAK <humair88@hotmail.com>2016-07-27 06:44:05 +0000
commit6fd4613d0bf1bb78340e46d45b269ddd3c36f190 (patch)
tree91a2a795aa56d96d076acf1b202645d0e68dd47a /node_modules/express-minify/cache.js
parent6271b9d13139c1e55118e5f26a3a7bf8caeeb11d (diff)
added compression
Diffstat (limited to 'node_modules/express-minify/cache.js')
-rw-r--r--node_modules/express-minify/cache.js71
1 files changed, 0 insertions, 71 deletions
diff --git a/node_modules/express-minify/cache.js b/node_modules/express-minify/cache.js
deleted file mode 100644
index 95dff37..0000000
--- a/node_modules/express-minify/cache.js
+++ /dev/null
@@ -1,71 +0,0 @@
-var fs = require('fs');
-var path = require('path');
-
-var FileCache = function (basePath) {
- this.basePath = basePath;
-};
-
-FileCache.prototype.get = function (hash, callback) {
- var destPath = this.basePath + hash;
- fs.readFile(destPath, {encoding: 'utf8'}, function (err, data) {
- if (err) {
- callback(err);
- return;
- }
- callback(null, data.toString());
- });
-};
-
-FileCache.prototype.put = function (hash, minized, callback) {
- var destPath = this.basePath + hash;
- var tempPath = destPath + '.tmp';
- // fix issue #3
- fs.writeFile(tempPath, minized, {encoding: 'utf8'}, function (err) {
- if (err) {
- callback(err);
- return;
- }
- fs.rename(tempPath, destPath, callback);
- });
-};
-
-var MemoryCache = function () {
- this.cache = {};
-};
-
-MemoryCache.prototype.get = function (hash, callback) {
- if (!this.cache.hasOwnProperty(hash)) {
- callback(new Error('miss'));
- } else {
- callback(null, this.cache[hash]);
- }
-};
-
-MemoryCache.prototype.put = function (hash, minized, callback) {
- this.cache[hash] = minized;
- callback();
-};
-
-/**
- * @param {String|false} cacheDirectory false == use memory cache
- */
-var Cache = function (cacheDirectory) {
- this.isFileCache = (cacheDirectory !== false);
- if (this.isFileCache) {
- // whether the directory is writeable
- cacheDirectory = path.normalize(cacheDirectory + '/').toString();
- try {
- fs.accessSync(cacheDirectory, fs.W_OK);
- } catch (ignore) {
- console.log('WARNING: express-minify cache directory is not writeable, fallback to memory cache.');
- this.isFileCache = false;
- }
- }
- if (this.isFileCache) {
- this.layer = new FileCache(cacheDirectory);
- } else {
- this.layer = new MemoryCache();
- }
-};
-
-module.exports = Cache;