[Groonga-commit] droonga/express-droonga at 97e2e0e [master] Put ResponseCacheEntry and isCachableRequest() under the namespace of a cache instance

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Mar 20 14:31:23 JST 2014


YUKI Hiroshi	2014-03-20 14:31:23 +0900 (Thu, 20 Mar 2014)

  New Revision: 97e2e0eb2eb239996b3ae59c414e683faeb04c67
  https://github.com/droonga/express-droonga/commit/97e2e0eb2eb239996b3ae59c414e683faeb04c67

  Message:
    Put ResponseCacheEntry and isCachableRequest() under the namespace of a cache instance

  Modified files:
    lib/response-cache.js

  Modified: lib/response-cache.js (+25 -9)
===================================================================
--- lib/response-cache.js    2014-03-20 14:12:47 +0900 (c793ae5)
+++ lib/response-cache.js    2014-03-20 14:31:23 +0900 (ede7d59)
@@ -32,14 +32,24 @@ function sendCachedResponse(response, cached) {
   response.end();
 }
 
-function ResponseCacheEntry(cache) {
+function Cache(options) {
+  options = normalizeOptions(options);
+  var cache = this.cache = createCache({
+    size: options.size
+  });
+
+this.isCachableRequest = function(request) {
+  return request.method == 'GET';
+};
+
+this.Entry = function ResponseCacheEntry(cache) {
   this.data = {
     status:  0,
     headers: {},
     body:    []
   };
 }
-ResponseCacheEntry.prototype = {
+this.Entry.prototype = {
   get cachable() {
     return this.data.status == 200;
   },
@@ -55,15 +65,21 @@ ResponseCacheEntry.prototype = {
   }
 };
 
-exports = module.exports = function(options) {
-  options = normalizeOptions(options);
+}
+Cache.prototype = {
+  'get': function(key, callback) {
+    return this.cache.get(key, callback);
+  },
+  'set': function(key, value, ttl, callback) {
+    return this.cache.set(key, value, ttl, callback);
+  }
+};
 
-  var cache = createCache({
-    size: options.size
-  });
+exports = module.exports = function(options) {
+  var cache = new Cache(options);
 
   return function(request, response, next) {
-    if (request.method != 'GET') {
+    if (!cache.isCachableRequest(request)) {
       next();
       return;
     }
@@ -83,7 +99,7 @@ exports = module.exports = function(options) {
         return;
       }
 
-      var entry = new ResponseCacheEntry();
+      var entry = new cache.Entry();
 
       response.write = function(chunk, encoding) {
         entry.write(chunk, encoding);
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index