[PWA] 18. Clean the photo cache

We cannot let photo always keep caching new data without clean the old data. If message is not display on the page anymore, we want to clean it. And also every 5 mins we want to clean the photo data.

export default function IndexController(container) {
    this._container = container;
    this._postsView = new PostsView(this._container);
    this._toastsView = new ToastsView(this._container);
    this._lostConnectionToast = null;
    this._dbPromise = openDatabase();
    this._registerServiceWorker();
    this._cleanImageCache();

    var indexController = this;

    setInterval(function () {
        indexController._cleanImageCache();
    }, 1000 * 60 * 5);

    this._showCachedMessages().then(function () {
        indexController._openSocket();
    });
}

_leanImageCache():

  • First, go to idb, get all the writtrs from the db and get the photos which we want to keep
  • Then open the photo cache and check the url exists in the list, if not then delete it.
IndexController.prototype._cleanImageCache = function () {
    return this._dbPromise.then(function (db) {
        if (!db) return;

        // TODO: open the ‘wittr‘ object store, get all the messages,
        // gather all the photo urls.
        //
        // Open the ‘wittr-content-imgs‘ cache, and delete any entry
        // that you no longer need.
        var photosToKeep = [];
        var tx = db.transaction(‘wittrs‘);
        return tx.objectStore(‘wittrs‘).getAll()
            .then(function(messages){
                messages.forEach(function(message){
                    if(message.photo){
                        photosToKeep.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(!photosToKeep.includes(url.pathname)){
                            cache.delete(request);
                        }
                    })
                })
            });
    });
};
时间: 2024-10-08 10:31:21

[PWA] 18. Clean the photo cache的相关文章

[PWA] 16. Clean IDB

When we save items to IndexDB, we need to think about clean the items or keep those in a short list. IndexController.prototype._onSocketMessage = function(data) { var messages = JSON.parse(data); this._dbPromise.then(function(db) { if (!db) return; v

[PWA] 15. Using The IDB Cache And Display Entries

We want to use IDB to store the wittr messages. The logic is when the page start: service worker will read the skeleton from the cache and show to the interface. read the message data from the IDB first instead of going to network. Show the data from

[PWA] 17. Cache the photo

To cache photo, You need to spreate cache db to save the photo. So in wittr example, we cache the text already, if there in the wittr there is photo, we will create cache for it, so next time we can fetch from cache. For the incoming photo, we also n

Distributed Cache Coherence at Scalable Requestor Filter Pipes that Accumulate Invalidation Acknowledgements from other Requestor Filter Pipes Using Ordering Messages from Central Snoop Tag

A multi-processor, multi-cache system has filter pipes that store entries for request messages sent to a central coherency controller. The central coherency controller orders requests from filter pipes using coherency rules but does not track complet

Multi-core compute cache coherency with a release consistency memory ordering model

A method includes storing, with a first programmable processor, shared variable data to cache lines of a first cache of the first processor. The method further includes executing, with the first programmable processor, a store-with-release operation,

buffer和cache怎么让你们解释的那么难理解?

对于一个即将踏上“系统运维”或者更加高大尚的工作“系统调优”,如果这不跟这两哥们搞好关系了,坑的不只有内存,更坑的是你拿着调优的钱却干着随时被调的活.因为作为一个系统运维人员来说监控和优化IO性能这是最有可能你生存下来的技能,为啥呢?因为你不仅给老板省了钱,还提高了机器的工作效率..虽然钱都进了老板兜里,但你渐渐地植入了他深深地脑海里,总有一天你比钱重要!好了闲话少扯,接下来说说这两个哥们到底是什么? 之前我自己也对到底buffer和cache是什么,有什么不同,什么时候用buffer,什么时候

docker1-1

(1).查看内核 [[email protected] yum.repos.d]$ uname -r 3.10.0-327.el7.x86_64 [[email protected] yum.repos.d]$ cat /etc/os-release   ## NAME="Red Hat Enterprise Linux Server" VERSION="7.2 (Maipo)"   ##rhel7.2版本 ID="rhel" ID_LIKE=&

Android之使用Android-query框架进行开发(一)(转载)

开发Android使用Android-query框架能够快速的,比传统开发android所要编写的代码要少得很多,容易阅读等优势. 下载文档及其例子和包的地址:http://code.google.com/p/android-query/ 以下内容是我学习的一些心得分享: 第一节: // 必须实现AQuery这个类 AQuery aq = new AQuery(view); // 按顺序分析:取得xml对应控件id,设置图片,设置可以显示,点击事件(方法someMethod必须是public修饰

Linux内核源码分析--内核启动之(1)zImage自解压过程(Linux-3.0 ARMv7) 【转】

转自:http://blog.chinaunix.net/uid-25909619-id-4938388.html 研究内核源码和内核运行原理的时候,很总要的一点是要了解内核的初始情况,也就是要了解内核启动过程.我在研究内核的内存管理的时候,想知道内核启动后的页表的放置,页表的初始化等信息,这促使我这次仔细地研究内核的启动代码. CPU在bootloader的帮助下将内核载入到了内存中,并开始执行.当然,bootloader必须为zImage做好必要的准备:  1. CPU 寄存器的设置: R0