Skip to content

Commit

Permalink
Made it so that you can set the expiration of the cache in user code
Browse files Browse the repository at this point in the history
  • Loading branch information
lmatteis committed Feb 6, 2012
1 parent 3cd1064 commit a4e9c73
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions war/WEB-INF/modules/googlestore.js
Expand Up @@ -73,6 +73,7 @@ var googlestore = (function(){
var q = new Query(kind);
var options = FetchOptions.Builder.withDefaults();
var cacheKey = null;
var expireSecs = null;
var self;
function filter(propertyName, operator, value) {
operator = filterOperators[operator] || operator;
Expand All @@ -96,8 +97,9 @@ var googlestore = (function(){
options = options.offset(offset);
return self;
}
function setCacheKey(key) {
function setCacheKey(key, secs) {
cacheKey = key;
if(secs) expireSecs = secs;
return self;
}
function fetch(num) {
Expand All @@ -113,8 +115,11 @@ var googlestore = (function(){
var preparedQuery = googlestore.datastore.prepare(q);
var ret = preparedQuery.asList(options).toArray();
if(cacheKey) {
// expire after 2 hours (7200 seconds)
memcache.put(cacheKey, ret, 7200);
// expire after expireSecs if it exists
if(expireSecs)
memcache.put(cacheKey, ret, expireSecs);
else
memcache.put(cacheKey, ret);
}
return ret;
}
Expand Down

0 comments on commit a4e9c73

Please sign in to comment.