Latest Shouts In The Shoutbox -- View The Shoutbox · Rules
  


  Closed to further repliesCreate New TopicCreate New Poll

 Working with "Shift.cache"
gunblaza
 Posted: Nov 2 2011, 09:27 AM
Quote
Custom title
Admin
92 Posts
Joined 5-August 11


Shift has a very easy to use cache system that uses localStorage and sessionStorage* functionality.

It also supports the ability to cache JSON, which can be very useful for many applications.

Below is the list of Shift.cache functions.

CODE
Shift.cache.isSupported();
Shift.cache.set(key, value);
Shift.cache.set(key,value,"json");
Shift.cache.fetch(key);
Shift.cache.fetch(key,"json");
Shift.cache.remove(key);


Key is the name of the cache that you are storing and value is the content.

For example
CODE
Shift.cache.set("Hello", "Hello world");
alert(Shift.cache.fetch("Hello"));


This will output an alert that says "Hello World". To remove that cache use
CODE
Shift.cache.remove("Hello");


JSON caching works the same way but involves a little more code.

CODE
var someObj = {
hello: "Hello",
world: " World"
};
Shift.cache.set("Hello", someObj, "json");
var someVar = Shift.cache.fetch("Hello", "json");
alert(someVar.hello + someVar.world);


This will output "Hello World" also.

*session storage is currently not supported until Shift 1.1


This is my signature
PM
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Share this topic:
« Next Oldest | Documentation | Next Newest »

Topic Options Closed to further repliesCreate New TopicCreate New Poll