Skip to content

Commit

Permalink
Keep the photo cache clean by checking the database for needed photos…
Browse files Browse the repository at this point in the history
…, then deleting any photos from the cache that are not needed
  • Loading branch information
karakarakaraff committed Jan 30, 2018
1 parent fecaad3 commit 8493cb3
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion public/js/main/IndexController.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,25 @@ IndexController.prototype._cleanImageCache = function() {
//
// Open the 'wittr-content-imgs' cache, and delete any entry
// that you no longer need.
var imagesNeeded = [];
var tx = db.transaction('wittrs');
return tx.objectStore('wittrs').getAll().then(function(messages) {
messages.forEach(function(message) {
if (message.photo) {
imagesNeeded.push(message.photo);
}
});
return caches.open('wittr-content-imgs');
}).then(function(cache) {
return cache.keys().then(function (requests) {
requests.forEach(function(request) {
var url = new URL(request.url);
if (!imagesNeeded.includes(url.pathname)) {
cache.delete(request);
}
});
});
});
});
};

Expand Down Expand Up @@ -191,4 +210,4 @@ IndexController.prototype._onSocketMessage = function(data) {
});

this._postsView.addPosts(messages);
};
};

0 comments on commit 8493cb3

Please sign in to comment.