You must Sign In to post a response.
  • Category: JQuery

    How to apply caching in jquery

    Hiiiii
    i have a requirement like when user selects any item in dropdown then that particular itel value should be in cache ,when page is loading if the cache is not null have to display to the user
    please provide sample code
  • #769682
    You have to keep the drop down selected value stuff into cookie or local storage/ session storage options to maintain cache.

    if you keep the value into document.cookie = newcookie where new cookie has the drop down value . when reloading page, check the cookie value if it has value then assign it otherwise make it as empty.

    another one, keep the value into local storage like collection or array or normal variable which are going to refer from master page.

    function Item_Cache() {
    var collection = {};

    function get_from_cache( item ) {
    if ( undefined === item) {
    collection[ item] = item;
    }

    return collection[ item];
    }

    return { get: get_from_cache };
    }

    so, based on collection here we will maintain items into cache.

    Thanks!
    B.Ramana Reddy


  • Sign In to post your comments