我试图将angular-cache模块用于我的项目,但不确定它是否正常工作。以下是代码 -
“angular-cache.caches.CenterCache.keys” = [http://localhost/Services/Tracker/api/Center]
在加载应用程序时,它会在控制台中打印“缓存不存在”的消息,它会在本地存储中创建缓存。 它创建了本地存储中的密钥 -
“angular-cache.caches.CenterCache.data.http:// localhost/Services/Tracker/api/Center” = mystoredvalue
创建了另一个密钥
var https = require('https');
var url = 'https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=1min&apikey=demo';
exports.handler = function (event, context) {
https.get(url, function(res) {
var data = '';
res.on('data', (chunk) => { data += chunk; });
res.on('end', () => { console.log("BODY: " + data); });
}).on('error', (e) => { console.log("Got error: " + e.message);});
};
问题 -
我觉得它不是从缓存中挑选数据。我错过了什么吗?
答案 0 :(得分:1)
也许您选择使用此结构;
angular.module('cacheApp', []).
controller('CacheCtrl', ['$scope', '$cacheFactory', function($scope, $cacheFactory) {
$scope.keys = [];
// get cacheFactory
$scope.cache = $cacheFactory('CenterCache');
// Custom put
// call function key and value
$scope.put = function(key, value) {
// Control cache
if (angular.isUndefined($scope.cache.get(key))) {
$scope.keys.push(key);
}
// Fill cache
$scope.cache.put(key, angular.isUndefined(value) ? null : value);
};
}]);
如果你想使用cookieStore
angular.module('cookieStoreExample', ['ngCookies'])
.controller('ExampleController', ['$cookieStore', function($cookieStore) {
// Fill cookie
$cookieStore.put('CenterCache', yourObject );
// Get cookie
var favoriteCookie = $cookieStore.get('CenterCache');
//If you want
// Removing a cookie
$cookieStore.remove('CenterCache');
}]);