# Proxy Cache的配置的12个指令

<mark style="color:blue;">**Proxy Cache机制**</mark>实际上是Nginx服务器提供的<mark style="color:blue;">**Web缓存机制**</mark>的一部分。

{% hint style="info" %} <mark style="color:blue;">**Buffer**</mark>和<mark style="color:blue;">**Cache**</mark>虽然都是用于提升IO吞吐效率的，但是它们是一对不同的概念，翻译成中文分别是“<mark style="color:blue;">**缓冲**</mark>”和“<mark style="color:blue;">**缓存**</mark>”两个词。

* <mark style="color:blue;">**Buffer**</mark>，**主要用于传输效率不同步或者优先级别不相同的设备之间传递数据**，一般通过对一方数据进行临时存放，再统一发送的办法传递给另一方，以降低进程之间的等待时间，保证速度较快的进程不发生间断，临时存放的数据一旦传送给另一方，这些数据本身也就没有用处了；
* <mark style="color:blue;">**Cache**</mark>，**主要用于将硬盘上已有的数据在内存中建立缓存数据，提高数据的访问效率**，对于过期不用的缓存可以随时销毁，但不会销毁硬盘上的数据。
  {% endhint %}

在Nginx服务器中，Porxy Buffer和Proxy Cache都与代理服务相关，主要用来提供客户端与被代理服务器之间的交互效率。

* <mark style="color:blue;">**Porxy Buffer**</mark>实现了被代理服务器响应数据的异步传输
* <mark style="color:blue;">**Proxy Cache**</mark>则主要实现Nginx服务器对客户端数据请求的快速响应

Nginx服务器在接收到被代理服务器的响应数据之后，一方面通过Porxy Buffer机制将数据传递给客户端，另一方面根据Proxy Cache的配置将这些数据缓存到本地硬盘上。当客户端下次要访问相同的数据时，Nginx服务器直接从硬盘检索到相应的数据返回给用户，从而减少与被代理服务器交互的时间。

<mark style="color:orange;">**Proxy Cache机制依赖于Porxy Buffer机制，只有在Porxy Buffer机制开启的情况下Proxy Cache的配置才发挥作用。**</mark>

{% hint style="info" %}
在Nginx服务器中还提供了另一种<mark style="color:blue;">**将被代理服务器数据缓存到本地**</mark>的方法<mark style="color:blue;">**Proxy Store**</mark>，与Proxy Cache的区别是，它对来自被代理服务器的响应数据，尤其是静态数据只进行简单的缓存，不支持缓存过期更新、内存索引建立等功能，但支持设置用户或用户组对缓存数据的访问权限。
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bohans.gitbook.io/devops/ngnix/ji-chu-zhi-shi/4.-nginx-fu-wu-qi-de-dai-li-fu-wu/4.3-nginx-fu-wu-qi-de-fan-xiang-dai-li-fu-wu/proxy-cache-de-pei-zhi-de-12-ge-zhi-ling.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
