From 6379d10daa8c59aa1cda3946ebdec8d40479481f Mon Sep 17 00:00:00 2001 From: Benjamin Pannell Date: Fri, 24 Apr 2015 16:33:51 +0200 Subject: [PATCH] Changed the way cache controllers are implemented --- lib/CacheDirector.js.map | 2 +- lib/CacheDirector.ts | 3 +++ lib/cacheControllers/IDDirector.js | 15 +++++++++++++-- lib/cacheControllers/IDDirector.js.map | 2 +- lib/cacheControllers/IDDirector.ts | 17 +++++++++++++++-- 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/lib/CacheDirector.js.map b/lib/CacheDirector.js.map index 5d0b8a0..9936aac 100644 --- a/lib/CacheDirector.js.map +++ b/lib/CacheDirector.js.map @@ -1 +1 @@ -{"version":3,"file":"CacheDirector.js","sourceRoot":"","sources":["CacheDirector.ts"],"names":[],"mappings":"AAMC"} \ No newline at end of file +{"version":3,"file":"CacheDirector.js","sourceRoot":"","sources":["CacheDirector.ts"],"names":[],"mappings":"AASC"} \ No newline at end of file diff --git a/lib/CacheDirector.ts b/lib/CacheDirector.ts index c034789..f1373a2 100644 --- a/lib/CacheDirector.ts +++ b/lib/CacheDirector.ts @@ -4,4 +4,7 @@ export = ICacheDirector; interface ICacheDirector { valid(object: T): boolean; buildKey(object: T): string; + + validQuery(conditions: any): boolean; + buildQueryKey(conditions: any): string; } \ No newline at end of file diff --git a/lib/cacheControllers/IDDirector.js b/lib/cacheControllers/IDDirector.js index 52cc05a..96c4d71 100644 --- a/lib/cacheControllers/IDDirector.js +++ b/lib/cacheControllers/IDDirector.js @@ -1,11 +1,22 @@ +var MongoDB = require('mongodb'); var IDCacheDirector = (function () { function IDCacheDirector() { } IDCacheDirector.prototype.valid = function (object) { - return object._id; + return !!object._id; }; IDCacheDirector.prototype.buildKey = function (object) { - return JSON.stringify(object._id); + if (object._id._bsontype == 'ObjectID') + return new MongoDB.ObjectID(object._id.id).toHexString(); + return object._id; + }; + IDCacheDirector.prototype.validQuery = function (conditions) { + return !!conditions._id; + }; + IDCacheDirector.prototype.buildQueryKey = function (conditions) { + if (conditions._id._bsontype == 'ObjectID') + return new MongoDB.ObjectID(conditions._id.id).toHexString(); + return conditions._id; }; return IDCacheDirector; })(); diff --git a/lib/cacheControllers/IDDirector.js.map b/lib/cacheControllers/IDDirector.js.map index 9419f96..502e352 100644 --- a/lib/cacheControllers/IDDirector.js.map +++ b/lib/cacheControllers/IDDirector.js.map @@ -1 +1 @@ -{"version":3,"file":"IDDirector.js","sourceRoot":"","sources":["IDDirector.ts"],"names":["IDCacheDirector","IDCacheDirector.constructor","IDCacheDirector.valid","IDCacheDirector.buildKey"],"mappings":"AAKA,IAAM,eAAe;IAArBA,SAAMA,eAAeA;IAQrBC,CAACA;IAPGD,+BAAKA,GAALA,UAAMA,MAAoBA;QACtBE,MAAMA,CAACA,MAAMA,CAACA,GAAGA,CAACA;IACtBA,CAACA;IAEDF,kCAAQA,GAARA,UAASA,MAAoBA;QACzBG,MAAMA,CAACA,IAAIA,CAACA,SAASA,CAACA,MAAMA,CAACA,GAAGA,CAACA,CAACA;IACtCA,CAACA;IACLH,sBAACA;AAADA,CAACA,AARD,IAQC;AAVD,iBAAS,eAAe,CAAC"} \ No newline at end of file +{"version":3,"file":"IDDirector.js","sourceRoot":"","sources":["IDDirector.ts"],"names":["IDCacheDirector","IDCacheDirector.constructor","IDCacheDirector.valid","IDCacheDirector.buildKey","IDCacheDirector.validQuery","IDCacheDirector.buildQueryKey"],"mappings":"AAEA,IAAO,OAAO,WAAW,SAAS,CAAC,CAAC;AAIpC,IAAM,eAAe;IAArBA,SAAMA,eAAeA;IAoBrBC,CAACA;IAnBGD,+BAAKA,GAALA,UAAMA,MAAoBA;QACtBE,MAAMA,CAACA,CAACA,CAACA,MAAMA,CAACA,GAAGA,CAACA;IACxBA,CAACA;IAEDF,kCAAQA,GAARA,UAASA,MAAoBA;QACzBG,EAAEA,CAACA,CAACA,MAAMA,CAACA,GAAGA,CAACA,SAASA,IAAIA,UAAUA,CAACA;YACnCA,MAAMA,CAACA,IAAIA,OAAOA,CAACA,QAAQA,CAACA,MAAMA,CAACA,GAAGA,CAACA,EAAEA,CAACA,CAACA,WAAWA,EAAEA,CAACA;QAC7DA,MAAMA,CAACA,MAAMA,CAACA,GAAGA,CAACA;IACtBA,CAACA;IAEDH,oCAAUA,GAAVA,UAAWA,UAAUA;QACjBI,MAAMA,CAACA,CAACA,CAACA,UAAUA,CAACA,GAAGA,CAACA;IAC5BA,CAACA;IAEDJ,uCAAaA,GAAbA,UAAcA,UAAUA;QACpBK,EAAEA,CAACA,CAACA,UAAUA,CAACA,GAAGA,CAACA,SAASA,IAAIA,UAAUA,CAACA;YACvCA,MAAMA,CAACA,IAAIA,OAAOA,CAACA,QAAQA,CAACA,UAAUA,CAACA,GAAGA,CAACA,EAAEA,CAACA,CAACA,WAAWA,EAAEA,CAACA;QACjEA,MAAMA,CAACA,UAAUA,CAACA,GAAGA,CAACA;IAC1BA,CAACA;IACLL,sBAACA;AAADA,CAACA,AApBD,IAoBC;AAtBD,iBAAS,eAAe,CAAC"} \ No newline at end of file diff --git a/lib/cacheControllers/IDDirector.ts b/lib/cacheControllers/IDDirector.ts index 3f12b11..628da94 100644 --- a/lib/cacheControllers/IDDirector.ts +++ b/lib/cacheControllers/IDDirector.ts @@ -1,14 +1,27 @@ /// 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; } } \ No newline at end of file