summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarren Smith <garren.smith@gmail.com>2014-02-05 19:23:12 +0200
committerGarren Smith <garren.smith@gmail.com>2014-02-05 19:23:12 +0200
commit8ec4cbc11e337555dd82e27e19c802bda3bcb817 (patch)
treee1cfc38317af69e0940619f56686bcc0b3c075e7
parented89f34020a10259344ded418785a4492159c23f (diff)
downloadcouchdb-fauxton-data-cache.tar.gz
Add more caching locationsfauxton-data-cache
-rw-r--r--src/fauxton/app/addons/databases/resources.js5
-rw-r--r--src/fauxton/app/addons/databases/routes.js2
-rw-r--r--src/fauxton/app/addons/databases/views.js2
-rw-r--r--src/fauxton/app/addons/documents/views.js21
-rw-r--r--src/fauxton/app/core/base.js21
-rw-r--r--src/fauxton/app/core/couchdbSession.js11
6 files changed, 37 insertions, 25 deletions
diff --git a/src/fauxton/app/addons/databases/resources.js b/src/fauxton/app/addons/databases/resources.js
index 5fa931b00..ea1aed243 100644
--- a/src/fauxton/app/addons/databases/resources.js
+++ b/src/fauxton/app/addons/databases/resources.js
@@ -171,6 +171,11 @@ function(app, FauxtonAPI, Documents) {
documentation: function(){
return "all_dbs";
},
+
+ cache: {
+ expires: 60
+ },
+
url: function(context) {
if (context === "apiurl") {
return window.location.origin + "/_all_dbs";
diff --git a/src/fauxton/app/addons/databases/routes.js b/src/fauxton/app/addons/databases/routes.js
index c41301826..131abf996 100644
--- a/src/fauxton/app/addons/databases/routes.js
+++ b/src/fauxton/app/addons/databases/routes.js
@@ -59,7 +59,7 @@ function(app, FauxtonAPI, Databases, Views) {
},
establish: function() {
- return [this.databases.fetch()];
+ return [this.databases.fetchOnce()];
}
});
diff --git a/src/fauxton/app/addons/databases/views.js b/src/fauxton/app/addons/databases/views.js
index afe2d1c11..7f23d6598 100644
--- a/src/fauxton/app/addons/databases/views.js
+++ b/src/fauxton/app/addons/databases/views.js
@@ -61,7 +61,7 @@ function(app, Components, FauxtonAPI, Databases) {
var deferred = FauxtonAPI.Deferred();
FauxtonAPI.when(currentDBs.map(function(database) {
- return database.status.fetch();
+ return database.status.fetchOnce();
})).always(function(resp) {
//make this always so that even if a user is not allowed access to a database
//they will still see a list of all databases
diff --git a/src/fauxton/app/addons/documents/views.js b/src/fauxton/app/addons/documents/views.js
index 547620330..13cbacb1b 100644
--- a/src/fauxton/app/addons/documents/views.js
+++ b/src/fauxton/app/addons/documents/views.js
@@ -1804,30 +1804,15 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum
template: "addons/documents/templates/changes",
initialize: function () {
- var that = this;
- this.listenTo( this.model.changes, 'change', function () {
- console.log('render on change');
- that.render();
- });
- this.listenTo( this.model.changes, 'cachesync', function () {
- console.log('render on cachesync');
- that.render();
- });
+ this.listenTo( this.model.changes, 'sync', this.render);
+ this.listenTo( this.model.changes, 'cachesync', this.render);
},
establish: function() {
- return [ this.model.changes.fetchOnce({prefill: true,
- success: function () {
- console.log('hi ajax success');
- },
- prefillSuccess: function () {
- console.log('hi prefill success');
- }
- })];
+ return [ this.model.changes.fetchOnce({prefill: true})];
},
serialize: function () {
- console.log('ss');
return {
changes: this.model.changes.toJSON(),
database: this.model
diff --git a/src/fauxton/app/core/base.js b/src/fauxton/app/core/base.js
index 6fe32618f..24b89cf55 100644
--- a/src/fauxton/app/core/base.js
+++ b/src/fauxton/app/core/base.js
@@ -17,7 +17,6 @@ define([
],
function(Backbone, LayoutManager, BackboneCache) {
- console.log(BackboneCache);
var FauxtonAPI = {
//add default objects
router: {
@@ -81,8 +80,24 @@ function(Backbone, LayoutManager, BackboneCache) {
var caching = {
fetchOnce: function (opts) {
var options = _.defaults(opts || {}, this.cache, {cache: true});
- console.log('opts', options);
- return this.fetch(options);
+
+ if (opts && !opts.cache) {
+ delete options.cache;
+ }
+
+ if (!options.prefill) {
+ return this.fetch(options);
+ }
+
+ //With Prefill, the Caching with resolve with whatever is in the cache for that model/collection
+ //and at the sametime it will fetch from the server the latest.
+ var promise = FauxtonAPI.Deferred(),
+ fetchPromise = this.fetch(options);
+
+ fetchPromise.progress(promise.resolveWith); // Fires when the cache hit happens
+ fetchPromise.then(promise.resolveWith); // Fires after the AJAX call
+
+ return promise;
}
};
diff --git a/src/fauxton/app/core/couchdbSession.js b/src/fauxton/app/core/couchdbSession.js
index 93bfd8ac6..b70ddf313 100644
--- a/src/fauxton/app/core/couchdbSession.js
+++ b/src/fauxton/app/core/couchdbSession.js
@@ -29,9 +29,16 @@ function (FauxtonAPI) {
fetchUser: function (opt) {
var that = this,
- currentUser = this.user();
+ options = opt || {},
+ currentUser = this.user(),
+ fetch = this.fetchOnce;
- return this.fetchOnce(opt).then(function () {
+ if (options.forceFetch) {
+ fetch = this.fetch;
+ Backbone.fetchCache.clearItem(_.result(this.url));
+ }
+
+ return this.fetch(opt).then(function () {
var user = that.user();
// Notify anyone listening on these events that either a user has changed