localStorage 캐시 도구 클래스

1315 단어 프런트 엔드
define(function(require) { require(“./context_holder”); var util = require(“UI/system/lib/base/util”);varjustep=require(“ U I/s y s t e m/l i b/b a s e/u t i l ” ) ; v a r j u s t e p = r e q u i r e ( “UI/system/lib/justep”);
var STCTools = {};

/**
 *  
 * 
 */
STCTools.addToCache = function(prefix,cacheName,value){

    util.setGlobalValue(prefix+"_"+cacheName,value);
};

/**
 *  
 */
STCTools.getValueFromCache = function(prefix,cacheName){
    return util.getGlobalValue(prefix+"_"+cacheName);
};

/**
 *  (localStorage )
 */
STCTools.save2DB = function(key,value){

    var storage = window.localStorage;
    if(storage && value){
        try{
            storage.setItem(key, JSON.stringify(value));
        }catch(e){
            console.log(e);
        }
    }
};

/**
 *  (localStorage )
 */
STCTools.deleteFromDB = function(key){
    var storage=window.localStorage;
    if(storage){
        storage.removeItem(key);
    }
};

/**
 *  (localStorage )
 */
STCTools.getFromDB = function(key){

    var storage=window.localStorage;
    var result = storage.getItem(key);

    try{
        return result?$.parseJSON(result):null;
    }catch(e){
        console.log(e);
        return null;
    }
};

window.STCTools = STCTools;
return STCTools;

});

좋은 웹페이지 즐겨찾기