[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);
}
})
})
});
});
};
[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. ...
- [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 ...
- [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 ...
- TMS320C64x DSP L1 L2 Cache架构(1)——C64x Cache Architecture
[前沿]研究生阶段从事于DSP和FPGA技术的相关研究工作,学习并整理了大量的技术资料,包括TI公司的官方文档和网络上的详细笔记,花费了大量的时间和精力总结了前人的工作成果.无奈工作却从事于嵌入式技术 ...
- 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 ...
- 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 ...
- ARM920T的Cache
转载自:http://www.eefocus.com/mcu-dsp/242034 ARM920T有16K的数据Cache和16K的指令Cache,这两个Cache是基本相同的,数据Cache多了一些 ...
- buffer和cache怎么让你们解释的那么难理解?
对于一个即将踏上“系统运维”或者更加高大尚的工作“系统调优”,如果这不跟这两哥们搞好关系了,坑的不只有内存,更坑的是你拿着调优的钱却干着随时被调的活.因为作为一个系统运维人员来说监控和优化IO性能这是 ...
- linux7buffer和cache
现象:作为hdfs集群的主节点,越来越卡 排查:CPU,mem CPU正常,检查内存情况,发现如下 如上截图:发现程序可用内存为91G,但是部分swap分区被占用.于是引出如下思考,free -h这条 ...
随机推荐
- 那些年,我们一起被坑的H5音频
原文地址:http://weibo.com/p/23041874d6cedd0102vkbr 不要被这么文艺的标题吓到,这里不会跟你讲述中学时期泡妞史,也不会有其它什么现实不该有而小说噼里啪啦不能 ...
- linux如何开机以命令行形式启动?
在管理员权限下,修改/etc/inittab文件即可.把id:5:initdefault:改为id:3:initdefault:就可以了. 如下图所示: 图1: . 图2:
- TestNG Listener
常用接口 IExecutionListener 监听TestNG运行的启动和停止. IAnnotationTransformer 注解转换器,用于TestNG测试类中的注解. ISuiteList ...
- Socket原理
一.Socket简介 Socket是进程通讯的一种方式,即调用这个网络库的一些API函数实现分布在不同主机的相关进程之间的数据交换. 几个定义: (1)IP地址:即依照TCP/IP协议分配给本地主机的 ...
- vertical-align:top属性
vertical-align这个是设置元素的垂直排列的. 用来定义行内元素的基线相对于该元素所在行的基线的垂直对齐. 它的值比较多:baseline | sub | super | top | tex ...
- shell 脚本中 命令
终端工具tput和stty是两款终端处理工具tput cols,lines,longname,cpu 100 100 输入密码时,不能让输入的内容显示出来.用stty #!/bin/bash #Fil ...
- you need to be root to perform this command linux
获得root权限如何获得:打开终端,输入su回车 然后输入密码回车就行了
- Trigger model Trigger expr_id in WorkFolow
For example, suppose you want to set a Sale Order into the state "Done" once it has been s ...
- tomcat源码阅读
1 工具准备 需要SVN.Maven.JDK.Eclipse.Eclipse M2插件 2 下载源码及发布包 源码在这里:http://svn.apache.org/repos/a ...
- Unity3D 3D横版跑酷
Unity3d 3D横版跑酷系列(Character Controller组件) @广州小龙 目前在做一个3D跑酷的横版游戏,目前说一下 Character Controller组件! 1.Slop ...