Home Backend Development PHP Tutorial 求教cache-control头的统制(影响了自己写的缓存功能了)

求教cache-control头的统制(影响了自己写的缓存功能了)

Jun 13, 2016 pm 12:26 PM
cache control

求教cache-control头的控制(影响了自己写的缓存功能了)
自己做了一个php控制的缓存,依靠etag和文件缓存来处理
如果浏览器发送了etag,则进行对比,etag一致,直接发送304,etag不一致,如果有文件缓存,则直接读取文件缓存,并发送当前服务器缓存的etag
(文件缓存和etag的更新在其他地方处理)

现在突然发现有响应没有返回304,一查,发现这个地址的服务器http响应头返回了cache-control:no-cache
我清空服务器的缓存后看,第一次响应的时候服务器就自动发送了一个no-cache头,(我的etag也发送了出去的),结果就是无论服务器端有没有缓存,浏览器都不会把etag添加到自己的请求头里面去,服务器端处理的时候没有收到etag,就当做是第一次请求,然后又重新读取文件缓存,又重新发送etag……(响应200)

大致是这么回事,但是这样就失去了我想用304来直接缓存的效果了。

看了一下区别,正常的数据,大概10KB,运行一直正常(没有缓存初次请求130ms,有缓存初次请求90ms,之后16ms或以下)
而没有发送304的这个(一直发送no-cache)的这个,数据只有304B,(但是就算不加缓存模块,因为服务器计算的原因,也要花90ms左右),
怀疑是不是因为数据返回不一致的原因而导致的,将这个304B的数据扩增到12KB,还是发送no-cache头,增加到20kb,也是一样的。

然后懵了……不知道怎么回事了。

(天地良心,代码全部是我写的,除了一个header(etag)外绝对没有发送其他的etag了)
------解决思路----------------------
原因是什么?
为什么会一直发送no-cache呢?估计是服务器设置了吧。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

After joining the company, I understood what Cache is After joining the company, I understood what Cache is Jul 31, 2023 pm 04:03 PM

The thing is actually like this. At that time, my leader gave me a perf hardware performance monitoring task. During the process of using perf, I entered the command perf list and I saw the following information: My task is to enable these cache events to be counted normally. But the point is, I have no idea what these misses and loads mean.

Why does using cache increase computer speed? Why does using cache increase computer speed? Dec 09, 2020 am 11:28 AM

Using the cache can increase the speed of the computer because the cache shortens the waiting time of the CPU. Cache is a small but high-speed memory located between the CPU and the main memory DRAM. The function of Cache is to increase the rate of CPU data input and output; Cache has a small capacity but fast speed, while the memory speed is low but has a large capacity. By optimizing the scheduling algorithm, the performance of the system will be greatly improved.

What is cache? What is cache? Nov 25, 2022 am 11:48 AM

Cache is called cache memory. It is a high-speed small-capacity memory between the central processing unit and the main memory. It is generally composed of high-speed SRAM. This kind of local memory is oriented to the CPU. It is introduced to reduce or eliminate the gap between the CPU and the memory. The impact of the speed difference between them on system performance. Cache capacity is small but fast, memory speed is low but capacity is large. By optimizing the scheduling algorithm, the performance of the system will be greatly improved.

Nginx Cache configuration plan and how to solve related memory usage problems Nginx Cache configuration plan and how to solve related memory usage problems May 23, 2023 pm 02:01 PM

5 options for nginx caching cache 1. One of the traditional caches (404) This method is to direct the 404 error of nginx to the backend, and then use proxy_store to save the page returned by the backend. Configuration: location/{root/home/html/;#Home directory expires1d;#Expiration time of the web page error_page404=200/fetch$request_uri;#404 ​​directed to the /fetch directory} Location/fetch/{#404 directed here internal ;#Indicates that this directory cannot be directly accessed externally

How to use cache in SpringBoot project How to use cache in SpringBoot project May 16, 2023 pm 02:34 PM

Preface Caching can effectively improve system performance and stability by storing frequently accessed data in memory, reducing the pressure on underlying data sources such as databases. I think everyone has used it more or less in their projects, and our project is no exception. However, when I was reviewing the company's code recently, the writing was very stupid and low. The rough writing is as follows: publicUsergetById(Stringid){Useruser=cache. getUser();if(user!=null){returnuser;}//Get user from the database=loadFromDB(id);cahce.put(id,user);returnu

nginx reverse proxy caching tutorial. nginx reverse proxy caching tutorial. Feb 18, 2024 pm 04:48 PM

Here is the tutorial for nginx reverse proxy caching: Install nginx: sudoaptupdatesudoaptinstallnginx Configure reverse proxy: Open nginx configuration file: sudonano/etc/nginx/nginx.conf Add the following configuration in the http block to enable caching: http{...proxy_cache_path /var/cache/nginxlevels=1:2keys_zone=my_cache:10mmax_size=10ginactive=60muse_temp_path=off;proxy_cache

What are the characteristics of cache, rom and ram? What are the characteristics of cache, rom and ram? Aug 26, 2022 pm 04:05 PM

Characteristics of cache: A one- or two-level high-speed, small-capacity memory set between the CPU and the main memory. The information is naturally lost when the computer is powered off. Characteristics of ROM: it can only read data from the memory, but cannot write information into it. The data will still exist after the computer is powered off. Characteristics of ram: it can read data from the memory and write information to the memory; it is used to store commands, programs and data required to run the program; information is naturally lost when the computer is powered off.

How to implement Caffeine+Redis second-level cache based on Spring Cache How to implement Caffeine+Redis second-level cache based on Spring Cache Jun 01, 2023 am 10:13 AM

The details are as follows: 1. Let’s talk about what is hard-coded cache? Before learning SpringCache, I often used caching in a hard-coded way. Let's take a practical example. In order to improve the query efficiency of user information, we use caching for user information. The sample code is as follows: @AutowireprivateUserMapperuserMapper; @AutowireprivateRedisCacheredisCache;//Query users publicUsergetUserById(LonguserId){//Define cache keyStringcacheKey= "userId_

See all articles