[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这条 ...
随机推荐
- newInstance()和new的区别
在初始化一个类,生成一个实例的时候:newInstance() 和 new 有什么区别?用newInstance与用new是有区别的,区别在于创建对象的方式不一样,前者是使用类加载机制,那么为什么会有 ...
- C#中Predicate的一点理解
本人喜欢代码看起来比较优雅,而C#真的是一种很优雅的语言.比如我们New List<string> StrList; 如果我们想查找StrList,可以使用C#提供的 StrList.Fi ...
- cmd 命令行下复制、粘贴的快捷键
1.单击左下角“开始”菜单,选择“运行”,输入“cmd”. 2.在弹出的cmd窗口的标题栏上点击“右键”,选择“属性”. 3.在弹出的对话框中选择“选项”这个选项卡,在“编辑选项”区域中勾选“快速编辑 ...
- 《vi中的替换艺术》-linux命令五分钟系列之十一
vi方面的内容不知道分类到哪里好,就放到<Linux命令五分钟系列>里吧! 今天编程,关于栈的一个小例子,其间我需要把”S.”替换为”S->”(替换不包括双引号). 其实这个不难,不 ...
- .animate动画
.animate(params, [duration], [easing], [callback]) params: 结果样式属性 duration: 动画时长 也可以用 slow normal fa ...
- Win7系统下完全删除Mysql
今天不知为什么Mysql服务器突然连接不上,于是胡乱折腾了一番,导致最后不得不重新安装Mysql.安装不成功,服务器起不来,就是最后那步的时候服务器启动不了,这是因为Mysql在卸载的时候没有彻底卸载 ...
- nginx 编译选项
内容有些多,一眼看来难免头昏脑胀,但坚持看完,相信你一定会有所收获. nginx参数: --prefix= 指向安装目录 --sbin-path 指向(执行)程序文件(nginx) --conf-pa ...
- 【Java】Hibernate4实战 之 第一部分Hibernate入门
Hibernate是什么:ORMapping的原理 Hibernate是轻量级的ORMapping框架. ORMapping基本规则: 类和表映射. 实例和数据库表中的一条数据映射. 实例的属性和数据 ...
- Instagram的技术架构
http://blogread.cn/it/article/5497 Instagram 被 Facebook 以10亿美金收购.团队规模:13 人.而在被Facebook收购前的一个月,整个团队才7 ...
- HAPROXY实习
没事玩玩,简单搞定. 同一个URL可以分发到后端不同的WEB上. STATS页画也刷出来了. 参考网址: http://www.cnblogs.com/kgdxpr/p/3272861.html 如果 ...