Skip to content

Commit

Permalink
Connection.database: Add options parameter to support disabling usage…
Browse files Browse the repository at this point in the history
… of the cache for specific databases.
  • Loading branch information
Adam Butcher authored and Adam Butcher committed Mar 5, 2019
1 parent 2852166 commit fb82e09
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/cradle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};

//
Expand Down
13 changes: 9 additions & 4 deletions lib/cradle/database/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down

0 comments on commit fb82e09

Please sign in to comment.