diff --git a/lib/cradle.js b/lib/cradle.js index 269f1ab..ec8f3b1 100644 --- a/lib/cradle.js +++ b/lib/cradle.js @@ -253,8 +253,8 @@ cradle.Connection.prototype.request = function (options, callback) { // We return an object with database functions, // closing around the `name` argument. // -cradle.Connection.prototype.database = function (name) { - return new cradle.Database(name, this) +cradle.Connection.prototype.database = function (name, opts) { + return new cradle.Database(name, this, opts) }; // diff --git a/lib/cradle/database/index.js b/lib/cradle/database/index.js index 15f193d..667352a 100644 --- a/lib/cradle/database/index.js +++ b/lib/cradle/database/index.js @@ -2,12 +2,17 @@ var querystring = require('querystring'), Args = require('vargs').Constructor, cradle = require('../../cradle'); -var Database = exports.Database = function (name, connection) { +var Database = exports.Database = function (name, connection, opts) { this.connection = connection; this.name = encodeURIComponent(name); - this.cache = new (cradle.Cache)(connection.options); + this.opts = {...connection.options}; + if (opts && opts.disableCache) { + this.opts.cache = false; + this.opts.cacheSize = 0; + } + this.cache = new (cradle.Cache)(this.opts); this.cacheFeed = null; - if (connection.options.cache === 'follow') { + if (this.opts.cache === 'follow') { var self = this; this.exists(function(err, result) { if (result === true) @@ -23,7 +28,7 @@ Database.prototype.configureCacheFeed = function () { } // For any entry already in the cache, update it if it changes // remotely. - if (this.connection.options.cache === 'follow') { + if (this.opts.cache === 'follow') { var self = this; this.changes(function (err, list) { var lastSeq = 0;