如何每天删除localstorage一次?

时间:2014-12-22 22:14:54

标签: javascript

我有以下代码在本地存储中缓存来自sharepoint的大量术语。 由于源数据可能每天更改一次或两次,我想包括如果它是新的一天,那么它应该获得新的数据。

应用程序被400人使用,因此缓存对其进行了大量改进,从15秒加载到不到1秒,但我需要确保至少一次加载新数据。

问题是:

我如何每天使此密钥无效?

function GetAllTermsRecursive(){
    if(typeof(Storage) !== "undefined") 
    {
        //Check if data has been cached.
        if(typeof(localStorage.Terms)  !== "undefined")
        {   
            var start = new Date().getTime();
            var terms=localStorage.Terms;
            var end = new Date().getTime();
            var time = end - start;
            alert('Execution time with cache: ' + time);
        }
        else
        {

            var start = new Date().getTime();
            //Current Context
            var context = SP.ClientContext.get_current();           
            //Current Taxonomy Session
            var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);           
            //Term Stores
            var termStores = taxSession.get_termStores();           
            //Name of the Term Store from which to get the Terms.
            var termStore = termStores.getByName("Taxonomy_kl5tZjInn7STsFTzIE7n3Q==");          
            //GUID of Term Set from which to get the Terms.
            var termSet = termStore.getTermSet("31da4bc1-6429-499a-9d5e-be5e18b13c87");         
            var terms = termSet.getAllTerms();          
            context.load(terms);

            context.executeQueryAsync(function(){   
                var termEnumerator = terms.getEnumerator(); 
                var termList = "Terms: \n";                 
                    while(termEnumerator.moveNext()){                       
                        var currentTerm = termEnumerator.get_current(); 
                        var currentTermPath = currentTerm.get_pathOfTerm().split(';');
                        var children = tree.children;
                        termList += currentTermPath.get_name(); 
                        termList += currentTerm.get_name() + "\n";              
                    }
                    localStorage.Terms = termList;
                    var end = new Date().getTime();
                    var time = end - start;
                    alert('Execution time: ' + time);               
                },function(sender,args){            
                      console.log(args.get_message());              
                    });
        }           
    }
    else {
            alert("Cache not sopported in old browsers, please upgrade");
    }   
}

0 个答案:

没有答案