Permalink
Browse files

replacing function with computed property

  • Loading branch information...
1 parent 27451e1 commit 73c7d200f3756a7c9730c2dfa919d0af405de481 @mauritslamers committed Nov 10, 2011
Showing with 15 additions and 16 deletions.
  1. +15 −16 lib/core/Session.js
View
@@ -60,7 +60,7 @@ exports.Session = SC.Object.extend({
_cid: 'thoth',
- _timeOutDurationCache: null, // to cache the calculation of timeOutDuration to milliseconds
+ //_timeOutDurationCache: null, // to cache the calculation of timeOutDuration to milliseconds
init: function(){
arguments.callee.base.apply(this, arguments);
@@ -78,14 +78,15 @@ exports.Session = SC.Object.extend({
return sInfoObj[sessionName];
},
- getTimeoutInMs: function(){
- var timeout_in_ms = this._timeOutDurationCache;
- if(!timeout_in_ms){ // if there is no cache yet, create it
- timeout_in_ms = this.timeOutDuration * 60 * 1000;
- this._timeOutDurationCache = timeout_in_ms;
- }
- return timeout_in_ms;
- },
+ timeoutInMs: function(){
+ return this.timeOutDuration * 60 * 1000;
+ // var timeout_in_ms = this._timeOutDurationCache;
+ // if(!timeout_in_ms){ // if there is no cache yet, create it
+ // timeout_in_ms = this.timeOutDuration * 60 * 1000;
+ // this._timeOutDurationCache = timeout_in_ms;
+ // }
+ // return timeout_in_ms;
+ }.property().cacheable(),
_userCacheObjects: {},
@@ -121,7 +122,7 @@ exports.Session = SC.Object.extend({
// walk through the _userCacheObjects object, find sessions that are overdue for removal
console.log('cleaning user cache');
var i,j,ses,sesCount,cache = this._userCacheObjects;
- var timeOut = this.getTimeoutInMs();
+ var timeOut = this.get('timeoutInMs');
var now = new Date().getTime();
for(i in cache){
sesCount = 0;
@@ -144,9 +145,9 @@ exports.Session = SC.Object.extend({
this.store.refreshRecord(sr,this._cid,function(response){
var cache = me.getUserCache.call(me,username,sessionKey); // make sure this-reference is correct
var uc, rec;
+ //sys.log('SessionModule: getSessionObject gets: ' + sys.inspect(response));
if(response){
rec = response.refreshResult;
- //sys.log('SessionModule: getSessionObject gets: ' + sys.inspect(rec));
if(!cache){ // if it doesn't exist, but it does in the sessionData, it should be resurrected
uc = UserCache.create().from(rec.sessionData);
me.setUserCache.call(me,username,sessionKey,uc);
@@ -168,7 +169,7 @@ exports.Session = SC.Object.extend({
if(record.userCache) record.userCache = null; // prepare for storing
var sr = API.createStoreRequest({ bucket: username, key: sessionKey, record: record}, this._ud, Constants.ACTION_UPDATE);
this.store.updateRecord(sr,this._cid,function(rec){
- me.getUserCache(username,sessionKey).lastSeen = new Date().getTime();
+ me.getUserCache(username,sessionKey).lastSeen = new Date().getTime();
if(callback) callback(rec);
});
},
@@ -204,21 +205,19 @@ exports.Session = SC.Object.extend({
if(this.invokeLater) this.invokeLater('cleanUserCache'); // check whether that does anything :)
// returns YES or NO depending on whether the user is still logged in
- var timeout_in_ms = this.getTimeoutInMs();
- sys.log('checkSession called... retrieving sessionObject...');
+ var timeout_in_ms = this.get('timeoutInMs');
this.getSessionObject(user,receivedSessionKey,function(rec){
var lastSeen,
now = new Date().getTime();
- sys.log('getSessionObject callback called...');
if(rec){
lastSeen = rec.lastSeen;
if((now - lastSeen) > timeout_in_ms){ // timeout, so delete session
me.destroySessionObject.call(me,user,receivedSessionKey);
if(callback) callback(false);
}
else { //active session
- rec.lastSeen = now;
+ rec.lastSeen = now; // update lastSeen and then save
me.saveSessionObject.call(me,user,receivedSessionKey,rec,function(){
if(callback) callback(true);
});

0 comments on commit 73c7d20

Please sign in to comment.