Warn on no setExpire in file store
This commit is contained in:
parent
92e0f579ca
commit
6e2955d60c
1
TODO.md
1
TODO.md
|
@ -3,3 +3,4 @@
|
||||||
* fix that chrome bug where it loads the doc twice
|
* fix that chrome bug where it loads the doc twice
|
||||||
* Add file extensions ourselves to push state
|
* Add file extensions ourselves to push state
|
||||||
* add feedback for errors to UI - esp. too long
|
* add feedback for errors to UI - esp. too long
|
||||||
|
* make sure file store still functions appropriately
|
||||||
|
|
|
@ -9,10 +9,11 @@ var hashlib = require('hashlib');
|
||||||
|
|
||||||
var FileDocumentStore = function(options) {
|
var FileDocumentStore = function(options) {
|
||||||
this.basePath = options.path || './data';
|
this.basePath = options.path || './data';
|
||||||
|
this.expire = options.expire;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Save data in a file, key as md5 - since we don't know what we could be passed here
|
// Save data in a file, key as md5 - since we don't know what we could be passed here
|
||||||
FileDocumentStore.prototype.set = function(key, data, callback, setExpire) {
|
FileDocumentStore.prototype.set = function(key, data, callback, skipExpire) {
|
||||||
try {
|
try {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
fs.mkdir(this.basePath, '700', function() {
|
fs.mkdir(this.basePath, '700', function() {
|
||||||
|
@ -22,6 +23,9 @@ FileDocumentStore.prototype.set = function(key, data, callback, setExpire) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
callback(true);
|
callback(true);
|
||||||
|
if (_this.expire && !skipExpire) {
|
||||||
|
winston.warn('file store cannot set expirations on keys');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -31,13 +35,17 @@ FileDocumentStore.prototype.set = function(key, data, callback, setExpire) {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get data from a file from key
|
// Get data from a file from key
|
||||||
FileDocumentStore.prototype.get = function(key, callback, setExpire) {
|
FileDocumentStore.prototype.get = function(key, callback, skipExpire) {
|
||||||
|
var _this = this;
|
||||||
fs.readFile(this.basePath + '/' + hashlib.md5(key), 'utf8', function(err, data) {
|
fs.readFile(this.basePath + '/' + hashlib.md5(key), 'utf8', function(err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
callback(false);
|
callback(false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
callback(data);
|
callback(data);
|
||||||
|
if (_this.expire && !skipExpire) {
|
||||||
|
winston.warn('file store cannot set expirations on keys');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue