angularJS应用程序中的缓存问题 [英] Caching issue in angularJS application

查看:124
本文介绍了angularJS应用程序中的缓存问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个管理面板,它是一个纯angularJS应用程序,它使用REST API进行数据处理.REST API是使用SlimAPI框架和Laravel的Eloquent ORM构建的.

I've an admin panel which is a pure angularJS application, which uses REST api for data manipulation. REST api is built using SlimAPI framework and Laravel's Eloquent ORM.

我在管理面板中遇到缓存问题.即使向系统添加了新内容,它也不会显示在列表页面中,除非并且直到我清除缓存并刷新它.

I'm facing caching issue in admin panel. Even though if a add new content to the system, it'll not show up in the list page until and unless I clear the cache and refresh it.

当他们向系统添加新内容时,我不能每次都要求客户端清除缓存.我的问题是:

I cannot ask my client to clear the cache everytime when they add new content to the system. My questions are:

  1. 有什么方法可以自动刷新缓存吗?
  2. 此问题是由于ORM还是由于angularJS发生的?

我很困惑,因为当我查看网络控制台时,来自API的响应也没有刷新.它将有旧数据.我怀疑有角JS是否使用缓存的响应而不向API发送请求.

I've this confusion because, when I look into network console, the response from API is also not refreshed one. It will have old data. I doubt whether angular JS using the cached responses without sending request to API.

我在本地计算机上没有遇到此问题,这仅在测试&生产服务器,我们无权进行调试.

I'm not facing this issue on my local machine, this is happening only on test & production servers, which we don't have access to debug.

在jQuery AJAX调用中,我们可以指定是否缓存响应并将其用于将来.angularJS是否有与此类似的设置?

In jQuery AJAX calls, we can specify whether to cache the responses and use it for future. Is there any setting similar to this in angularJS?

响应标题放置在测试和生产应用程序中:

Remote Address:**:**:**:**
Request URL:http://********/admin/articles/getall
Request Method:GET
Status Code:200 OK (from cache)

响应标题

Cache-Control:max-age=2592000
Content-Length:1343
Content-Type:application/json; charset=utf-8

本地计算机上的响应标题

Remote Address:[::1]:80
Request URL:http://localhost/admin/articles/getall
Request Method:GET
Status Code:200 OK

响应标题

view source
Connection:Keep-Alive
Content-Length:10201
Content-Type:application/json; charset=utf-8
Date:Thu, 18 Jun 2015 06:01:11 GMT
Keep-Alive:timeout=5, max=99
Server:Apache/2.4.9 (Win64) PHP/5.5.12
Status-Line:HTTP/1.1 200 OK
X-Powered-By:PHP/5.5.12

请求标头

view source
Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Authorization:X-token $2a$10$aba34954ce887ad829384u3jHt43CvxcvFMOW/sqAYgI6DgF8OydG
Connection:keep-alive
Host:localhost
Referer:http://localhost/admin/
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36
X-token:$2a$10$aba34954ce887ad829384u3jHt43CvxcvFMOW/sqAYgI6DgF8OydG

推荐答案

除非您声明,否则angular不会缓存您的 $ http 请求,因此服务器很可能会缓存这些值.

Unless you state it, angular will not cache your $http requests, so most likely the values are being cached by your server.

您可以做几件事:

  1. 将标头传递给服务器以忽略缓存(假设您的服务器将对该标头做出适当的反应)
  2. 在$ http请求中添加一个随机参数,以便服务器将您的请求解释为新请求.

对此问题的答案为1和2: Angular IE缓存问题为$ http

Answers number 1 and 2 on this question: Angular IE Caching issue for $http

这篇关于angularJS应用程序中的缓存问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆