博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[PWA] 18. Clean the photo cache
阅读量:4686 次
发布时间:2019-06-09

本文共 2170 字,大约阅读时间需要 7 分钟。

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);                        }                    })                })            });    });};

 

转载于:https://www.cnblogs.com/Answer1215/p/5516091.html

你可能感兴趣的文章
redis数据结构--String
查看>>
POJ 3279 Fliptile (二进制枚举)
查看>>
memcached 细究(三)
查看>>
future
查看>>
关于main函数传参数的问题
查看>>
getTickCount()函数 VS GetTickCount()函数
查看>>
嵌入式jetty
查看>>
2017~回顾分享
查看>>
let const var的区别与作用
查看>>
计算出线在屏幕内的最长坐标
查看>>
使用svn——项目的目录布局
查看>>
Linux学习之CentOS(二十五)--Linux磁盘管理:LVM逻辑卷基本概念及LVM的工作原理
查看>>
【bzoj4310/hdu5030-跳蚤】后缀数组
查看>>
深度信任网络的快速学习算法(Hinton的论文)
查看>>
RSA System.Security.Cryptography.CryptographicException
查看>>
s的封装和信息隐蔽
查看>>
excelhttp://www.cnblogs.com/caoyuanzhanlang/p/3591904.html
查看>>
ArrayList和LinkedList和Vector源码分析
查看>>
webservice整合spring cxf
查看>>
再次编译这个应用程序应该不会有问题
查看>>