alexmingoia / sticky Goto Github PK
View Code? Open in Web Editor NEWSimple, key/value pair browser-storage cache leveraging the latest HTML5 storage APIs.
Simple, key/value pair browser-storage cache leveraging the latest HTML5 storage APIs.
Is there a way to list all stored keys?
It would be nice if StickStore.get
supported an extra 'default' argument.
At present:
var foo = store.get('foo');
if (foo === null) {
foo = 'bar';
}
This would be nicer done as:
var foo = store.get('foo', 'bar')
Then, if the key foo
doesn't exist, it'll return the value 'bar'
.
(Python's dict.get
does this. Basically, it's basically def get(self, key, default=None)
.)
Rationale: It's very useful for configuration stores as this will probably be used a lot for as it means that you don't need to worry about whether an option is set but can take a default value immediately and easily.
IE10 uses msIndexedDB
in ie10pp4. you can betatest it on browserstack
Opera is maybe implementing it.
so you might want to add those prefixes in
First of all, thanks for this library!
Because of this check it is impossible to save falsy values, like the number 0 or an empty string, which are real usecases.
It should check for undefined/null instead. I'd be happy to provide a PR, but I don't know if @alexmingoia is still involved with this project to accept it.
目前只是方便浏览器存储,如果能方便的进行与服务器同步就非常好了!
I got an email alerting me to a performance problem with large data sets. Sticky persists everything to memory, which is partly because it's an easy way of providing synchronous functionality for webSQL/indexedDB's asynchronous methods.
Ideally, there is no need for a memory cache. Sticky should avoid it and use setTimeout trickery to retain synchronous functionality.
I'm working on trying to use sticky for a project and I've got a bit of code I've written to generate dummy data...
You can see all of my code here: http://pastebin.com/sSnTH5PH
Anyway, This bit appears to be the offending piece when I initialize Stickystore...
var store = new StickyStore({
adapters: ['webSQL', 'indexedDB', 'localStorage'],
ready:function(){
console.log("Database loaded");
},
size:200
});
If I remove the adapters option - it runs fine. If I keep the adapters option - I get the following error in Chrome:
Uncaught TypeError: Cannot read property 'index' of undefined
StickyStore.exec/html5/js/sticky-2.8.js:181
StickyStore.set/html5/js/sticky-2.8.js:292
GetMyJSONbuildjson.js:84
(anonymous function)/html5/#:645
f.Callbacks.njquery-1.7.1.min.js:2
f.Callbacks.o.fireWithjquery-1.7.1.min.js:2
e.extend.readyjquery-1.7.1.min.js:2
c.addEventListener.Bjquery-1.7.1.min.js:2
/html5/#:620
Any ideas?
So 'Sticky' is EXACTLY what I've been looking for. I've been searching for something like this for ages...
I've wanted to build an HTML5 app but needed a way to abstract the storage situation - but I'm looking to deal with a high volume of data (50,000 - 100,000 records or more). I know WebSQL could handle it - but I'm not so sure about IndexedDB, LocalStorage, or GlobalStorage (certainly not cookies).
I ran a test and was able to get 20,000 records to store... but sometimes it seems hard to tell which storage method is active in Chrome and firefox doesn't seem to have a way to let you peek into the datastore.
One other thing I found was that removeall did seem to fail in chrome (despite a callback of true)... so I'm not sure what I was doing wrong.
I think there's a question in here somewhere... but I think it'd be nice to see just how hard we can push these data storage methods...
It'd be great to have tests for this, so we can confirm all the various adapters are working as expected.
Cheers
From what I've read it sounds like IndexedDB can store most JS objects directly without needing to serialize... have you considered supporting this?
Does sticky fires an event then? How is this handled?
Sticky now doesn't work on the new FireFox 10.
The error info "This error occurred because an operation was not allowed on an object. A retry of the same operation would fail unless the cause of the error is corrected."
http://www.mozilla.org/en-US/firefox/10.0/releasenotes/
In release notes they mentioned "We've added IndexedDB APIs to more closely match the specification".Looks like the FF team updated the IndexedDB API on FF 10.
https://dvcs.w3.org/hg/IndexedDB/raw-file/3ac0182139b3/Speclet_020_IDB_API_Constructs.html
Hi, thanks for Sticky. Opera Mini/Mobile and Firefox for Mobile are supported?
I have built a workaround for an exception that we are getting when I login with an invalid user then a valid user. The code is at about line 438 in sticky.js:
request.onsuccess = function (event) {
if (event.target.result &&
(!store.adapters.indexedDB.io ||
store.adapters.indexedDB.io.name !== ((event.target.result.db) ? event.target.result.db.name : event.target.result.name))) {
// FF is event.target.result, Chrome is event.target.result.db
store.adapters.indexedDB.io = (event.target.result.db) ? event.target.result.db : event.target.result
}
// Backwards compatibility for older indexedDB implementations before
// IDBDatabase.setVersion() was removed.
As opposed to
request.onsuccess = function (event) {
// FF is event.target.result, Chrome is event.target.result.db
if (!store.adapters.indexedDB.io && event.target.result) {
store.adapters.indexedDB.io = (event.target.result.db) ? event.target.result.db : event.target.result
}
// Backwards compatibility for older indexedDB implementations before
// IDBDatabase.setVersion() was removed.
Comments?
Kevin
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.