Skip to content

Commit

Permalink
Merge pull request persvr#52 from kriszyp/master
Browse files Browse the repository at this point in the history
Various updates
  • Loading branch information
kriszyp committed Oct 4, 2013
2 parents cf99c17 + 31ff8ce commit 693bc9f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 17 deletions.
6 changes: 4 additions & 2 deletions README.md
Expand Up @@ -655,8 +655,10 @@ undefined, and primitive function constructors (String, Number, etc.)

mySetting = require("perstore/util/settings").mySetting;

This module parses the JSON in the local.json file found in the current working directory
and puts all the properties on the module's export.
This module will first look for settings in a local.json file found in the current working directory,
if it is not available (and you are using node), it will use the [rc configuration loader](https://github.com/dominictarr/rc)
(if you have it installed) to load settings, using the app name of "persvr", and puts all the properties on the module's export.
If you are using node, installing rc (npm install rc) and putting your settings in a .persvrrc file is recommended.

### extend-error

Expand Down
2 changes: 1 addition & 1 deletion facet.js
Expand Up @@ -353,7 +353,7 @@ var SchemaControlled = function(facetSchema, sourceClass, permissive){
// this handles query results, but probably should create a branch for real arrays
var results = LazyArray({
some: function(callback){
source.some(function(item){
return source.some(function(item){
callback((item && typeof item == "object" && wrap(item, transaction, item, true)) || item);
});
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "perstore",
"version": "0.3.2",
"version": "0.3.3",
"author": "Kris Zyp",
"email": "kriszyp@gmail.com",
"contributors": ["Vladimir Dronnikov <dronnikov@gmail.com>"],
Expand Down
23 changes: 16 additions & 7 deletions store/cache.js
Expand Up @@ -16,7 +16,7 @@ exports.Cache = function(store, cacheStore, options){
now = new Date().getTime();
if(now > nextCheck){
nextCheck = now + cleanupInterval;
return when(cacheStore.query("expires<$1", {parameters:[now]}), function(results){
return when(cacheStore.query("_expires<$1", {parameters:[now]}), function(results){
results.forEach(function(object){
cacheStore["delete"](object.id);
});
Expand All @@ -39,9 +39,8 @@ exports.Cache = function(store, cacheStore, options){
},
put: function(object, id){
cleanup();
if(!object.expires){
object.autoExpires = true;
object.expires = new Date().getTime() + defaultExpiresTime;
if(!object._expires){
setExpires(object);
}
if(cacheWrites){
cacheStore.put(object, id);
Expand All @@ -52,9 +51,8 @@ exports.Cache = function(store, cacheStore, options){
},
add: function(object, id){
cleanup();
if(!object.expires){
object.autoExpires = true;
object.expires = new Date().getTime() + defaultExpiresTime;
if(!object._expires){
setExpires(object);
}
if(cacheWrites){
cacheStore.add(object, id);
Expand All @@ -74,4 +72,15 @@ exports.Cache = function(store, cacheStore, options){
cacheStore["delete"](id);
}
};
function setExpires(object){
Object.defineProperty(object, '_expires', {
value: new Date().getTime() + defaultExpiresTime,
enumerable: false
});
Object.defineProperty(object, '_autoExpires', {
value: true,
enumerable: false
});
}
};

19 changes: 13 additions & 6 deletions util/settings.js
Expand Up @@ -10,10 +10,17 @@ if(!read){
}
try{
var settings = JSON.parse(read("local.json").toString("utf8"));
for(var i in settings){
exports[i] = settings[i];
}
}catch(e){
e.message += " trying to load local.json, make sure local.json is in your current working directory";
throw e;
}
settings = require("rc")("persvr",{
"processes": 2,
"port": 8082,
"repl": true,
"replPort": 5555,
"security":{
},
"dataFolder": "data"
});
}
for(var i in settings){
exports[i] = settings[i];
}

0 comments on commit 693bc9f

Please sign in to comment.