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. css样式积累

    1.圆角:     border-radius:16px 16px 16px 16px;     2透明度:             filter: alpha(opacity=80);       ...

  2. IS打包

    1. 目的 让用户可以通过运行一个安装程序,安装程序到系统中正常运行. 2. 注意 当我们用项目向导生成的新项目时,InstallShield只为我们生成两个事件,分别是OnFirstUIBefore ...

  3. JS设置Cookie,及COOKIE的限制

    在Javascript脚本里,一个cookie 实际就是一个字符串属性.当你读取cookie的值时,就得到一个字符串,里面当前WEB页使用的所有cookies的名称和值.每个cookie除了 name ...

  4. 常用排序算法集合-C实现

    之前熟悉C的时候写着玩的,就当做笔记用吧: #include<stdio.h> #include<stdlib.h> #include<string.h> #inc ...

  5. glide简介

    golang包管理工具glide简介   golang包管理工具glide简介 前言 golang是一个十分有趣,简洁而有力的开发语言,用来开发并发/并行程序是一件很愉快的事情.在这里我感受到了其中一 ...

  6. Objective-c之NSCopying

    Objective-c之NSCopying     copy的原理: 执行<NSCopying>协议,类中必须实现copyWithZone:方法响应的copy消息. copy消息将发送co ...

  7. iOS: 获取文件路径

    iOS: 获取文件路径   // 例如 - (NSString *)applicationDocumentsDirectory { return [NSSearchPathForDirectories ...

  8. iOS手写2048--基于Xcode7.1

    闲着没事自己想了下,半天写出来了,没有美化,只是实现了基本的2048,被我改成了A.B.C.D.E: 没有游戏开发经验,完全基于uiview 和 一大堆逻辑计算,如果你有指针.链表的使用经验,应该会很 ...

  9. Struts2之ajax初析

    Web2.0的随波逐流,Ajax那是大放异彩,Struts2框架自己整合了对Ajax的原生支持(struts 2.1.7+,之前的版本可以通过插件实现),框架的整合只是使得JSON的创建变得异常简单, ...

  10. MySql的rpm安装

    MySQL 5.5(rpm格式)在Linux 上安装 Linux系统上安装MySQL 5.5prm 1.准备工作 从MySQL官网上分别下载mysql服务器端于客户端包. 下载步骤:Downloads ...