using memoize function with underscore.js

前端 未结 3 1936
猫巷女王i
猫巷女王i 2021-02-05 18:05

I am trying to cache the result from an ajax call using memoize function from Underscore.js. I am not sure of my implementation. Also how to retrieve b

3条回答
  •  猫巷女王i
    2021-02-05 18:54

    If you are using Angular.js's $http, you probably just want to pass {cache : true} as a second parameter to the get method.

    To store values using key value pairs, you may want to use $cacheFactory, as described in other answers like here. Basically:

    var cache = $cacheFactory('cacheId');
    cache.put('states', 'value');
    cache.get('states');
    

提交回复
热议问题