Skip to content

Commit

Permalink
Changed the way cache controllers are implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Apr 24, 2015
1 parent c6282ca commit 6379d10
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/CacheDirector.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions lib/CacheDirector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ export = ICacheDirector;
interface ICacheDirector {
valid<T>(object: T): boolean;
buildKey<T>(object: T): string;

validQuery(conditions: any): boolean;
buildQueryKey(conditions: any): string;
}
15 changes: 13 additions & 2 deletions lib/cacheControllers/IDDirector.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/cacheControllers/IDDirector.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions lib/cacheControllers/IDDirector.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
/// <reference path="../../_references.d.ts" />
import cacheDirector = require('../CacheDirector');
import MongoDB = require('mongodb');

export = IDCacheDirector;

class IDCacheDirector implements cacheDirector{
valid(object: { _id: any }) {
return object._id;
return !!object._id;
}

buildKey(object: { _id: any }) {
return JSON.stringify(object._id);
if (object._id._bsontype == 'ObjectID')
return new MongoDB.ObjectID(object._id.id).toHexString();
return object._id;
}

validQuery(conditions) {
return !!conditions._id;
}

buildQueryKey(conditions) {
if (conditions._id._bsontype == 'ObjectID')
return new MongoDB.ObjectID(conditions._id.id).toHexString();
return conditions._id;
}
}

0 comments on commit 6379d10

Please sign in to comment.