# Ignore part of URL to force caching?

**URL:** <https://www.ruby-forum.com/t/ignore-part-of-url-to-force-caching/223450>\
**Category:** NGINX\
**Created:** [October 4, 2012, 8:21pm UTC](https://www.ruby-forum.com/t/ignore-part-of-url-to-force-caching/223450 "2012-10-04T20:21:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [October 4, 2012, 8:21pm UTC](https://www.ruby-forum.com/t/ignore-part-of-url-to-force-caching/223450/1 "2012-10-04T20:21:45Z")

</div>

I would like to “override” the intent of the app server that is  
basically disabling any caching of the backend file. For example, they  
are embedding a “noCache=#######” parameter at the end of the URL (there  
are other parameters following, but if I can check the url up-to the “?”  
that would suit me fine).

This is actually a dynamically generated SWF file, but the file is then  
constant for a reasonable amount of time such that I’d like to cache it  
for a few minutes.

Is there a way in a specific “location” to tell nginx to ignore the  
parameters (or any portion of the URL) when determining the cached  
object for that URL? In other words, tell nginx to cache content for  
that location, say only 5min, and ignore all parameters when determining  
whether to cache and how to match cached content?

If I’m not explaining myself properly, please let me know and I’ll try  
another route. 🙂

Thanks in advance,  
AJ

---

<div class="post-metadata">

**Author:** ![AJ\_Weber](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8c91f0/32.png) [@AJ\_Weber](https://www.ruby-forum.com/u/AJ_Weber)\
**Post date:** [October 5, 2012, 11:50am UTC](https://www.ruby-forum.com/t/ignore-part-of-url-to-force-caching/223450/2 "2012-10-05T11:50:05Z")

</div>

On 4 Out 2012 20h20 CEST, removed\_email\_address@domain.invalid wrote:

> I would like to “override” the intent of the app server that is  
> basically disabling any caching of the backend file. For example,  
> they are embedding a “noCache=#######” parameter at the end of the  
> URL (there are other parameters following, but if I can check the  
> url up-to the “?” that would suit me fine).
> 
> This is actually a dynamically generated SWF file, but the file is  
> then constant for a reasonable amount of time such that I’d like to  
> cache it for a few minutes.

> Is there a way in a specific “location” to tell nginx to ignore the  
> parameters (or any portion of the URL) when determining the cached  
> object for that URL? In other words, tell nginx to cache content  
> for that location, say only 5min, and ignore all parameters when  
> determining whether to cache and how to match cached content?

If I understand correctly. Inside your main cached location you can do:

if ($request\_uri ~\* noCache) {  
return 418;  
}

error\_page 418 =200 @other-cached-location;

And add @other-cached-location:

location @other-cached-location {  
# Set your cache parameters here and serve the content.  
}

— appa

---

<div class="post-metadata">

**Author:** ![AJ\_Weber](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8c91f0/32.png) [@AJ\_Weber](https://www.ruby-forum.com/u/AJ_Weber)\
**Post date:** [October 5, 2012, 12:08pm UTC](https://www.ruby-forum.com/t/ignore-part-of-url-to-force-caching/223450/3 "2012-10-05T12:08:48Z")

</div>

On Thu, Oct 04, 2012 at 02:20:30PM -0400, AJ Weber wrote:

> Is there a way in a specific “location” to tell nginx to ignore the  
> parameters (or any portion of the URL) when determining the cached  
> object for that URL? In other words, tell nginx to cache content for  
> that location, say only 5min, and ignore all parameters when determining  
> whether to cache and how to match cached content?
> 
> If I’m not explaining myself properly, please let me know and I’ll try  
> another route. 🙂

You can use “proxy\_cache\_key”:  
[http://nginx.org/en/docs/http/ngx\_http\_proxy\_module.html#proxy\_cache\_key](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_key)

For example, to completly ignore query strings:

location /swf/ {  
…  
proxy\_cache …  
proxy\_cache\_valid 5m;  
proxy\_cache\_key $proxy\_host$uri;  
}

or to account query strings parameters ONE and TWO:

location /swf/ {  
…  
proxy\_cache …  
proxy\_cache\_valid 5m;  
proxy\_cache\_key $proxy\_host$uri?$arg\_ONE&$arg\_TWO;  
}

–  
Igor S.

> **[Technical Support for NGINX and NGINX Plus Software](https://www.nginx.com/support/)**
>
> Get the help you need with support directly from the authors and maintainers of NGINX Open Source and NGINX Plus.

---

<div class="post-metadata">

**Author:** ![AJ\_Weber](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8c91f0/32.png) [@AJ\_Weber](https://www.ruby-forum.com/u/AJ_Weber)\
**Post date:** [October 5, 2012, 12:09pm UTC](https://www.ruby-forum.com/t/ignore-part-of-url-to-force-caching/223450/4 "2012-10-05T12:09:58Z")

</div>

On Fri, Oct 05, 2012 at 11:49:12AM +0200, Antnio P. P. Almeida wrote:

> > cache it for a few minutes.  
> > return 418;  
> > }
> 
> error\_page 418 =200 @other-cached-location;
> 
> And add @other-cached-location:
> 
> location @other-cached-location {  
> # Set your cache parameters here and serve the content.  
> }

There is proxy\_cache\_key for this.

–  
Igor S.

> **[Technical Support for NGINX and NGINX Plus Software](https://www.nginx.com/support/)**
>
> Get the help you need with support directly from the authors and maintainers of NGINX Open Source and NGINX Plus.

---

<div class="post-metadata">

**Author:** ![AJ\_Weber](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8c91f0/32.png) [@AJ\_Weber](https://www.ruby-forum.com/u/AJ_Weber)\
**Post date:** [October 5, 2012, 12:20pm UTC](https://www.ruby-forum.com/t/ignore-part-of-url-to-force-caching/223450/5 "2012-10-05T12:20:29Z")

</div>

On 5 Out 2012 12h09 CEST, removed\_email\_address@domain.invalid wrote:

> > > This is actually a dynamically generated SWF file, but the file is  
> > > If I understand correctly. Inside your main cached location you can  
> > > location @other-cached-location {
> > 
> > # Set your cache parameters here and serve the content.
> > 
> > }
> 
> There is proxy\_cache\_key for this.

I was under the impression that there wasn’t a specific location for  
the swf files. If there is in fact the proxy already has all you need  
for doing it much easier.

— appa

---

<div class="post-metadata">

**Author:** ![AJ\_Weber](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8c91f0/32.png) [@AJ\_Weber](https://www.ruby-forum.com/u/AJ_Weber)\
**Post date:** [October 5, 2012, 5:46pm UTC](https://www.ruby-forum.com/t/ignore-part-of-url-to-force-caching/223450/6 "2012-10-05T17:46:29Z")

</div>

This worked exactly as Igor described.

Thank you!  
-AJ
