# Cache only if no args?

**URL:** <https://www.ruby-forum.com/t/cache-only-if-no-args/199949>\
**Category:** NGINX\
**Created:** [December 1, 2010, 9:17pm UTC](https://www.ruby-forum.com/t/cache-only-if-no-args/199949 "2010-12-01T21:17:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [December 1, 2010, 9:17pm UTC](https://www.ruby-forum.com/t/cache-only-if-no-args/199949/1 "2010-12-01T21:17:35Z")

</div>

Hello all,

I have a small question for you !

It is possible to cache the response from proxy\_pass (that is filtered  
by custom filters) _only_ if the request has no args? If the request has  
arguments, it should be served from upstream and any temporary buffer  
dumped.

Example :

Request [http://www.example.com/image.jpg](http://www.example.com/image.jpg) ← cache it  
Request [http://www.example.com/image.jpg?lowquality=true](http://www.example.com/image.jpg?lowquality=true) ← don’t cache  
it

All assuming that the proxy\_cache\_key is just the uri without params  
($scheme://$http\_host$uri in the specific).

So, I should have only one copy of the file in cache and should be the  
“clean” one. I don’t want to cache any request that is processed by my  
custom filters with different cache keys.

Thank you very much 🙂

Kind regards,

Paolo Iannelli

Posted at Nginx Forum:

> **[Cache only if no args?](https://forum.nginx.org/read.php?2,154876,154876#msg-154876)**
>
> Hello all, I have a small question for you ! It is possible to cache the response from proxy\_pass (that is filtered by custom filters) \_only\_ if the request has no args? If the request has arguments, it should be served from upstream and any...

---

<div class="post-metadata">

**Author:** ![p.iannelli](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/838e76/32.png) [@p.iannelli](https://www.ruby-forum.com/u/p.iannelli)\
**Post date:** [December 1, 2010, 9:21pm UTC](https://www.ruby-forum.com/t/cache-only-if-no-args/199949/2 "2010-12-01T21:21:23Z")

</div>

On Wed, Dec 01, 2010 at 03:16:36PM -0500, p.iannelli wrote:

> Request [http://www.example.com/image.jpg](http://www.example.com/image.jpg) ← cache it  
> Request [http://www.example.com/image.jpg?lowquality=true](http://www.example.com/image.jpg?lowquality=true) ← don’t cache  
> it
> 
> All assuming that the proxy\_cache\_key is just the uri without params  
> ($scheme://$http\_host$uri in the specific).
> 
> So, I should have only one copy of the file in cache and should be the  
> “clean” one. I don’t want to cache any request that is processed by my  
> custom filters with different cache keys.

Get nginx-0.8.53 and

proxy\_cache\_bypass $args;  
proxy\_no\_cache $args;

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![p.iannelli](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/838e76/32.png) [@p.iannelli](https://www.ruby-forum.com/u/p.iannelli)\
**Post date:** [December 1, 2010, 9:37pm UTC](https://www.ruby-forum.com/t/cache-only-if-no-args/199949/3 "2010-12-01T21:37:44Z")

</div>

Hi Igor,

if I understood right :

proxy\_cache\_bypass bypass directly the cache and serve the response from  
the upstream.  
proxy\_no\_cache then prevent the response to be cached, unconditionally,  
after is fetched from upstream.

Your solution, then, may fit indeed my needs, thanks ! 🙂

I would like also to ask you if is possible to check whether a full  
cached file is present in proxy cache and, if yes, I would like to use  
my filter on that file instead of upstream. How may I check if a file is  
already in cache? Can I do it in config file? If not, how should I  
handle this in my module?

Thank you for you time !

Kind regards,

Paolo Iannelli

Posted at Nginx Forum:

> **[Re: Cache only if no args?](https://forum.nginx.org/read.php?2,154876,154886#msg-154886)**
>
> Hello all, I have a small question for you ! It is possible to cache the response from proxy\_pass (that is filtered by custom filters) \_only\_ if the request has no args? If the request has arguments, it should be served from upstream and any...
