No description, website, or topics provided.
JavaScript PHP
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
README
clearLocalStorage.html
client-cached.js
countData.php
getData.php
index.html
setup-db.sql

README

client-cached.js: An object to cache data on the client side

(C) 2010 Alberto Zaccagni - http://www.lazywithclass.com
MIT LICENSE


See included code for a working example.


- Setup
jQuery is required, so add it.
The init function has to be called before using the library.
You can invoke it in the following ways:

a) the results are checked for change every delay seconds, the count got from the
server call is compared to the cached count.
If the two numbers are different then a search on the server is allowed and the results in the cache are refreshed, so
it is the cached count 

CLIENTCACHED.init({
    id: 'search.jsp?parameter=value',
    resultsDivId: 'results',
    resultsCountUrl: 'countData.php',
    delay: 300
});


b) if a search is performed after the delay has passed the results are taken from the server and those
in the cache are refreshed

clientCached.init({
    id: 'unique',
    resultsDivId: 'results',
    delay: 300
});

The id attribute refers to the element's id where your data will be stored, it might be a good 
practice to set it as the POST url with all the parameters, so to have it tailored 
to what the user searched.


- Usage 

The following is just an example to show how to use the cached results.


if(! CLIENTCACHED.canUseCachedData()){
    console.log("taking data from the server");
    ajaxCall();
}else{
    console.log("taking data from the localStorage");
    CLIENTCACHED.populateResults();
}

As of now adding the following line is necessary for the library to get notified that the data is arrived:

$('#results').trigger('customAction');

I've read that jQuery offers a way to listen when data populates an element, so this will be in the following releseas I think.