2017-04-13 14 views
0

私は、存在する場合、sessionStorageから辞書を返すことになっている関数を持っています。そうでなければ、APIからの辞書をsessionStorageにロードして辞書を返します。sessionStorageからの処理に非常に時間がかかります

self.getDictionary = function(dictionary){ 
     var deferred = $q.defer(); 
     var saved_dictionary = JSON.parse($window.sessionStorage.getItem('dictionary_' + dictionary)); 

     if (saved_dictionary && saved_dictionary !== "null"){ 
      deferred.resolve(saved_dictionary); 
     } else { 
      var apiData = {module: "Dictionaries", method: "getDictionary", data: {name: dictionary}}; 
      apiService.execute(apiData).then(function (response) { 
       $window.sessionStorage.setItem('dictionary_' + dictionary, JSON.stringify(response)); 
       deferred.resolve(response); 
      }); 
     } 
     return deferred.promise; 
    }; 

非常に大きな(約0.5mbのJSON)可能性があるので、私は辞書をキャッシュしようとしています。

サンプル辞書:

{"DictionaryName":"Gaming","DictionaryCategory":[{"CategoryName":"Games","MandatoryAtLeast":1,"CategoryWords":[{"title":"zelda","score":1,"exact":true,"mandatory":false,"reject":false},{"title":"mass effect","score":1,"exact":false,"mandatory":true,"reject":false},{"title":"pokemon","score":1,"exact":false,"mandatory":true,"reject":false},{"title":"fallout","score":1,"exact":false,"mandatory":false,"reject":false},{"title":"cs:go","score":1,"exact":true,"mandatory":false,"reject":false},{"title":"sims","score":1,"exact":false,"mandatory":false,"reject":false},{"title":"until dawn","score":1,"exact":false,"mandatory":false,"reject":false},{"title":"deus ex","score":1,"exact":false,"mandatory":false,"reject":false},{"title":"skyrim","score":1,"exact":false,"mandatory":true,"reject":false}]},{"CategoryName":"Companies","MandatoryAtLeast":1,"CategoryWords":[{"title":"bioware","score":1,"exact":false,"mandatory":true,"reject":false},{"title":"bethesda","score":1,"exact":false,"mandatory":false,"reject":false},{"title":"steam","score":1,"exact":false,"mandatory":true,"reject":false},{"title":"valve","score":1,"exact":false,"mandatory":false,"reject":false},{"title":"alienware","score":1,"exact":false,"mandatory":false,"reject":false}]},{"CategoryName":"other","MandatoryAtLeast":1,"CategoryWords":[{"title":"gamer","score":1,"exact":false,"mandatory":true,"reject":false},{"title":"mods","score":1,"exact":false,"mandatory":false,"reject":false},{"title":"horror","score":1,"exact":false,"mandatory":false,"reject":false},{"title":"survival","score":1,"exact":true,"mandatory":false,"reject":false},{"title":"multiplayer","score":1,"exact":false,"mandatory":false,"reject":false},{"title":"action","score":1,"exact":true,"mandatory":true,"reject":false},{"title":"fps","score":1,"exact":false,"mandatory":true,"reject":false},{"title":"shooter","score":1,"exact":false,"mandatory":false,"reject":false},{"title":"mmo","score":1,"exact":false,"mandatory":true,"reject":false}]}]} 

問題はキャッシュから辞書を提供することを支援されていないということです。遠隔のAPIから読み込むのに要するように、sessionStorageからの辞書を提供するのにほとんど時間がかかります。

なぜsessionStorageから戻ってくるのに時間がかかりますか?

+0

'JSON.parse()'を呼び出す前に 'sessionStorage'でキーが定義されているのをチェックしないのはなぜですか? – guest271314

+0

私はできると思いますが、私はそれが大きな違いをもたらすとは思っていません。私が知る限り、null値でJSON.parse()を呼び出すと、無視されます –

+0

どのくらいの時間がかかりますか?時間はどのような問題になりますか? – charlietfl

答えて

0

デバッグ後、問題はsessionStorageではないようです。

問題は、AngularJSが1000歳以上の要素のng-repeatをレンダリングする時代です。それは私が調べなければならない次のものです

関連する問題