从版本开始,13.0.0将.angular在根目录中生成一个文件夹,该文件夹会被 git 忽略,其中包含一个cache缓存构建的文件夹。
如何删除(或清除)此缓存?
我试图将angular-cache模块用于我的项目,但不确定它是否正常工作.以下是代码 -
angular.module('TrackerApp').factory('TrackerFactory', function ($resource, CacheFactory) {
if (!CacheFactory.get('CenterCache')) {
console.log('cache does not exists');
CacheFactory.createCache('CenterCache', {
maxAge: 5 * 60 * 1000,
deleteOnExpire: 'aggressive'
});
}
var centerCache = CacheFactory.get('CenterCache');
var CenterClass = $resource(_ServiceBaseURL + 'api/Center/:id',{},{
query: {
method: 'GET',
cache: centerCache,
isArray:true
}
});
CenterClass.GetMultipleAsObject = function () { return this.query(); };
return {
CenterClass: CenterClass
};
});
Run Code Online (Sandbox Code Playgroud)
在加载应用程序时,它会在控制台中打印"缓存不存在"的消息,它会在本地存储中创建缓存.它创建了本地存储的关键 -
“angular-cache.caches.CenterCache.keys” = [http://localhost/Services/Tracker/api/Center]
Run Code Online (Sandbox Code Playgroud)
另一个关键是创建
“angular-cache.caches.CenterCache.data.http:// localhost/Services/Tracker/api/Center” = mystoredvalue
Run Code Online (Sandbox Code Playgroud)
问题 -
我觉得它不是从缓存中挑选数据.我错过了什么吗?
caching local-storage angularjs angular-cache angular-local-storage
我创建了一个UserService,如下所示:
angular.module('nrApp').factory('userService', ['Restangular', 'UserModel', 'DSCacheFactory', function (Restangular, UserModel, DSCacheFactory) {
// Create a new cache called "profileCache"
var userCache = DSCacheFactory('userCache', {
maxAge: 3600000,
deleteOnExpire: 'aggressive',
storageMode: 'localStorage', // This cache will sync itself with `localStorage`.
onExpire: function (key, value) {
Restangular.oneUrl('users', key).get().then(function(data) {
userCache.put(key, data);
});
}
});
Restangular.extendModel('users', function(obj) {
return UserModel.mixInto(obj);
});
Restangular.addRequestInterceptor(function(element, operation, what, url) {
if(operation === 'get') {
debugger;
//Check the cache to see if the resource is already cached
var data = userCache.get(url); …Run Code Online (Sandbox Code Playgroud) 我们的应用程序使用 node.js Core & Angular 7.2 版
我们经常推出 Angular 应用程序的生产版本,以便在一个月内部署 3-4 次更改。
我收到了一些客户的投诉,他们无法看到更改,除非他们清除缓存或在浏览器中硬重新加载页面。
我认为ng build --prod创建了唯一的哈希值,以便处理缓存破坏,但似乎没有发生。
在angular.json我有以下用于生产构建的配置
"production": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": false,
"vendorChunk": false,
"buildOptimizer": true,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
]
}
Run Code Online (Sandbox Code Playgroud)
运行后ng build --prod它会生成散列文件,它与基于更改的先前版本不同。此外,我已将服务器配置为不缓存index.html. 那么为什么有时用户需要硬重新加载页面或手动清除缓存以获取最新更改?
除了告诉客户清除他们的缓存之外,我还有什么办法可以解决这个问题?
任何建议将不胜感激。
我对$ templateCache资源有点困惑;
html /模板将存储在服务器端?
或者将存储在浏览器内存中?如果是这样的内存限制是什么?
使用此应用程序:https : //billiving-qa.azurewebsites.net/spa1/#/invoices
一些 http 调用应该被缓存,但由于某种原因这不起作用:
function getStatuses() {
return $http.get('/v1/definitions/status', { cache: true })
.then(function (response) {
return response.data;
})
}
Run Code Online (Sandbox Code Playgroud)
如果您查看网络,您会看到“v1/definitions/status”未缓存,尽管设置了标志。
谢谢