大佬教程收集整理的这篇文章主要介绍了如何将到期时间应用于HTML5 indexeddb中的键?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在考虑将值包装在具有当前日期时间和到期时间的对象中,当您获得该值时,请检查时差,但这是最好的方法吗?
谢谢
var open = indexedDB.open('demo'); open.onupgradeneeded = function() { var db = open.result; var store = db.createObjectStore('store'); var index = store.createIndex('timestamp','timestamp'); // Populate with some dummy data,with about half from the past: for (var id = 0; id < 20; ++id) { store.put({ value: Math.random(),timestamp: new Date(Date.Now() + (Math.random()-0.5) * 10000) },id); } }; open.onsuccess = function() { var db = open.result; var tx = db.transaction('store','readwrite'); // Anything in the past: var range = IDBKeyRange.upperBound(new Date()); tx.objectStore('store').index('timestamp').opencursor(rangE) .onsuccess = function(E) { var cursor = e.target.result; if (!cursor) return; console.log('deleting: ' + cursor.key); cursor.delete(); cursor.conTinue(); }; // This transaction will run after the first commits since // it has overlapping scope: var tx2 = db.transaction('store'); tx2.objectStore('store').count().onsuccess = function(E) { console.log('records remaining: ' + e.target.result); }; };
以上是大佬教程为你收集整理的如何将到期时间应用于HTML5 indexeddb中的键?全部内容,希望文章能够帮你解决如何将到期时间应用于HTML5 indexeddb中的键?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。