2014-05-23 44 views
1

我为我的应用程序之一使用phonegap,它很大程度上取决于localStorage。我已经写了使用传统的getItem和JS的setItem我所有的代码像下面提高iPhone4设备(iOS7)中的本地存储性能

localStorage.setItem(key, val) 

localStorage.getItem(key) 

它运作良好,在Android中,但iPhone4采用iOS7运行这将是非常缓慢的。我该如何改进localStorage的性能。

回答

1

我已经为下面的localStorage写了一个小包装,现在它像一个魅力一样工作,如果有人感兴趣请使用它,请让我知道是否有更好的解决方案。

var LStorage = (function() { 
    function LStorage() { 
     this.localStorage = JSON.parse(JSON.stringify(localStorage)); 
    } 
    LStorage.prototype.setItem = function (key, val) { 
     this.localStorage[key] = val; 
     localStorage.setItem(key, val); 
    }; 
    LStorage.prototype.getItem = function (key, undef) { 
     var val = this.localStorage[key]; 
     return val; 
    }; 
    LStorage.prototype.removeItem = function (key) { 
     delete this.localStorage[key]; 
     localStorage.removeItem(key); 
     return true; 
    }; 
    return LStorage; 
})(); 

谢谢。