[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.
IndexController.prototype._onSocketMessage = function(data) {
var messages = JSON.parse(data);
this._dbPromise.then(function(db) {
if (!db) return;
var tx = db.transaction('wittrs', 'readwrite');
var store = tx.objectStore('wittrs');
messages.forEach(function(message) {
store.put(message);
});
// TODO: keep the newest 30 entries in 'wittrs',
// but delete the rest.
//
// Hint: you can use .openCursor(null, 'prev') to
// open a cursor that goes through an index/store
// backwards.
store.index('by-date').openCursor(null, 'prev')
.then((cursor)=>{
return cursor.advance(); // only 30 itmes are kept
}).then(function deleteCursor(cursor){
if(!cursor){
return;
}else{
cursor.delete();
return cursor.continue().then(deleteCursor);
}
})
});
this._postsView.addPosts(messages);
};
[PWA] 16. Clean IDB的更多相关文章
- [PWA] 18. Clean the photo cache
We cannot let photo always keep caching new data without clean the old data. If message is not displ ...
- Hexo博客美化之蝴蝶(butterfly)主题魔改
Hexo是轻量级的极客博客,因为它简便,轻巧,扩展性强,搭建部署方便深受广大人们的喜爱.各种琳琅满路的Hexo主题也是被各种大佬开发出来,十分钦佩,向大佬仰望,大声称赞:流批!!! 我在翻看各种主 ...
- ubuntu6.04安装
一.在windows操作系统下准备ubuntu系统的安装盘 1. 下载ubuntu的ISO文件 这一步相对简单,网络上面有很多的链接下载.这里贴一个ubuntu的官方网站链接,可以下载到ubuntu ...
- javascript:base.superclass.constructor.call(this,config)
javascript中类的继承机制如下,有一个baseClass的类,然后为其定义两个方法,someMethod()和overwriteMethod() 1 var BaseClass = funct ...
- i.mx53开发的一些问题
i.mx53开发的一些问题 转载于此:http://blog.csdn.net/shell_albert/article/details/8242288 原来i.mx53上4GB的Nand Fla ...
- 对freescale的mfgtool的ucl2.xml的理解
转载于此:http://blog.csdn.net/bugouyonggan/article/details/8664898 对于Freescale MFG编程工具控制文件ucl2.xml的分析 为了 ...
- 将linux和uboot集成到Android编译框架中
span::selection, .CodeMirror-line > span > span::selection { background: #d7d4f0; }.CodeMirror ...
- Spring框架之jms源码完全解析
Spring框架之jms源码完全解析 我们在前两篇文章中介绍了Spring两大核心IOC(Inversion of Control控制反转)和AOP(Aspect Oriented Programmi ...
- [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 ...
随机推荐
- xml 个人练习2
package cn.gdpe.xml; import java.io.File;import java.io.FileInputStream;import java.io.IOException;i ...
- python使用VBA:Excel创建图表(转)
# -*- coding: utf-8 -*- """ Created on Thu Mar 06 11:22:03 2014 @author: Administrato ...
- Iis 日志文件默认路径
Iis 日志文件默认路径: C:\WINDOWS\system32\LogFiles
- Android单元测试初探——Instrumentation(转载)
学习Android有一段时间了,虽然前段时间对软件测试有了一些了解,不过接触android的单元测试却是头一次.这几天在物流大赛上也用了不少时间,所以对于android的单元测试没有太深入的研究,所以 ...
- psql rank row
rank() OVER (PARTITION BY f1 ORDER BY f2 DESC) ROW_NUMBER() () OVER (PARTITION BY f1 ORDER BY f2 DES ...
- 使用 Scut 搭建通服架构
整体通服的架构图如下: 整体思路: 尽量将公共的业务逻辑分拆到单个业务服务器: 公共业务RDB读写分离,提高IO并发量: 角色简要信息.角色战斗信息修改后将ID压入修改队列,简要信息每3分钟通知同步一 ...
- iOS触摸事件处理
iOS触摸事件处理 主要是记录下iOS的界面触摸事件处理机制,然后用一个实例来说明下应用场景. 一.处理机制 界面响应消息机制分两块, (1)首先在视图的层次结构里找到能响应消息的那个视图. (2 ...
- 在zend studio 9.* 中使用phpunit进行单元测试
单元测试在用PHP开发大型项目时必备的减少测试难度和提高测试效率的利器,而PHPUnit是php做单元测试时使用范围最广的一个.如果在window系统中开发,就要调用控制台来运行phpunit,非常的 ...
- jquery 插件JTable使用
http://www.jtable.org/ 下载后增加: Add these lines to the HEAD section of your HTML document: <!-- Inc ...
- 【转】BLE 学习记录
原文网址:http://m.blog.csdn.net/blog/chiooo/43985401 BLE 学习记录 ANROID BLE 开发,基于 bluetoothlegatt 分析 mBluet ...