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

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

  1. [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. ...

  2. [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 wil ...

  3. [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 te ...

  4. TMS320C64x DSP L1 L2 Cache架构(1)——C64x Cache Architecture

    [前沿]研究生阶段从事于DSP和FPGA技术的相关研究工作,学习并整理了大量的技术资料,包括TI公司的官方文档和网络上的详细笔记,花费了大量的时间和精力总结了前人的工作成果.无奈工作却从事于嵌入式技术 ...

  5. 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 ...

  6. 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 ...

  7. ARM920T的Cache

    转载自:http://www.eefocus.com/mcu-dsp/242034 ARM920T有16K的数据Cache和16K的指令Cache,这两个Cache是基本相同的,数据Cache多了一些 ...

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

    对于一个即将踏上“系统运维”或者更加高大尚的工作“系统调优”,如果这不跟这两哥们搞好关系了,坑的不只有内存,更坑的是你拿着调优的钱却干着随时被调的活.因为作为一个系统运维人员来说监控和优化IO性能这是 ...

  9. linux7buffer和cache

    现象:作为hdfs集群的主节点,越来越卡 排查:CPU,mem CPU正常,检查内存情况,发现如下 如上截图:发现程序可用内存为91G,但是部分swap分区被占用.于是引出如下思考,free -h这条 ...

随机推荐

  1. linuxC编程实战 my_server.c例子问题总结

    今天看linux C 编程实战的my_server例子时,敲到这段代码,对其父子进程关闭socket 进行close调用产生疑问 如图中标注的三个close socket,思考子进程通信结束 关闭自己 ...

  2. HTML5拖放API

    拖放事件事件提供了拖放可以控制几乎所有方面的拖放操作.棘手的部分是确定每个事件触发:在拖项目火:别人火下降的目标.拖动项时,以下事件(按照这个顺序): 拖曳开始拖dragend此刻你把鼠标按钮和开始移 ...

  3. php之框架增加日志记录功能类

    <?php /* 思路:给定文件,写入读取(fopen ,fwrite……) 如果大于1M 则重写备份 传给一个内容, 判断大小,如果大于1M,备份 小于则写入 */ class Log{ // ...

  4. php之分页类代码

    /* 思路 1.把地址栏的URL获取 2.分析URL中的query部分--就是?后面传参数的部分 3.query部分分析成数组 4.把数组中的page单元,+1,-1,形成2个新的数组 5.再把新数组 ...

  5. ecshop数据库操作类

    ECShop v2.7.2没有使用一些开源的数据库操作类,比如adodb或者PEAR,而是封装了自己的实现. 好处:实现非常轻量,只有一个文件,27Kb,大大减小了分发包的文件大小. 当网站需要做me ...

  6. jquery html 动态添加元素绑定事件

    由于实际的需要,有时需要往网页中动态的插入HTML内容,并在插入的节点中绑定事件处理函数.我们知道,用Javascript向HTML文档中 插入内容,有两种方法, 一种是在写HTML代码写入JS,然后 ...

  7. nginx 编译选项

    内容有些多,一眼看来难免头昏脑胀,但坚持看完,相信你一定会有所收获. nginx参数: --prefix= 指向安装目录 --sbin-path 指向(执行)程序文件(nginx) --conf-pa ...

  8. To Build A Dev Env On Linux(Ubuntu)

    Step1:System Installing 1)use iso image to Step2:Configuration Step3:Software Installing Step4:Other ...

  9. C# mvc3 mvc4 伪静态及IIS7.5配置

    mvc3 mvc4路由配置 //单独路由 routes.MapRoute(    name: "XXX",    url: "Home/XXX.html/{id}&quo ...

  10. 转:C++中 #ifdef 和#endif的作用

    一般情况下,源程序中所有的行都参加编译.但是有时希望对其中一部分内容只在满足一定条件才进行编译,也就是对一部分内容指定编译的条件,这就是"条件编译".有时,希望当满足某条件时对一组 ...