proxy_cache - Is there a way to cancel file caching from header filter?
Anatoli Marinov
toli at webforge.bg
Wed Apr 13 15:50:04 MSD 2011
I succeed to remove the file after it is saved in tmp directory and
before to be moved in cache directory.
The patch is little bit ugly :)
I added new variable in
struct ngx_http_request_s {
.....................
.....................
.....................
ngx_http_event_handler_pt write_event_handler;
#if (NGX_HTTP_CACHE)
ngx_http_cache_t *cache;
+ ngx_int_t do_not_cache;
#endif
ngx_http_upstream_t *upstream;
.....................
.....................
.....................
}
In the function ngx_http_upstream_process_request I modified the code
that moves the file from tmp to cache dir:
.........................
.........................
.........................
#if (NGX_HTTP_CACHE)
if (u->cacheable) {
if (p->upstream_done) {
+ if(r->do_not_cache){
+ ngx_http_file_cache_free(r->cache, u->pipe->temp_file);
+ } else {
ngx_http_file_cache_update(r, u->pipe->temp_file);
+ }
} else if (p->upstream_eof) {
/* TODO: check length & update cache */
+ if(r->do_not_cache){
+ ngx_http_file_cache_free(r->cache, u->pipe->temp_file);
+ } else {
ngx_http_file_cache_update(r, u->pipe->temp_file);
+ }
} else if (p->upstream_error) {
ngx_http_file_cache_free(r->cache, u->pipe->temp_file);
}
}
#endif
.........................
.........................
.........................
Now from any filter when I have instance of request structure I can set
r->do_not_cache and the file will not be saved in cache directory.
This approach is not so good because there is overhead when saving the
file in tmp ... and this file will not be used later.
Other ideas?
Cheers
Toli
On 04/13/2011 01:49 PM, Anatoli Marinov wrote:
> On 04/13/2011 12:47 PM, Igor Sysoev wrote:
>> On Wed, Apr 13, 2011 at 12:03:29PM +0300, Anatoli Marinov wrote:
>>> Hello,
>>> Is there a way to cancel file caching from header filter?
>>>
>>> I am using nginx as a reverse proxy and proxy_cache for caching and
>>> this
>>> configuration serves flv files.
>>>
>>> Standard flv module cannot work with proxy_cache so start= argument is
>>> not understand by the nginx. There is other internal server
>>> (typically a
>>> cloud of them) that understands the argument and return a chunk from
>>> the
>>> file - starting from desired position. After this file is received from
>>> the nginx by its upstream it will be cached.
>>>
>>> These chunked files should not been cached because they do not contain
>>> the whole content of the original file.
>>> So I have written new header filter and in this filter for given file I
>>> can take a decision to cache it or not. By default proxy_cache will
>>> cache this file so can I cancel this?
>> The simplest way is to set "X-Accel-Expires: 0" in a response
>> of server that sends chunk.
>>
>> Other way in configuration:
>>
>> proxy_cache_bypass $arg_start;
>> proxy_nocache $arg_start;
>>
>>
> I do not think I will be able to achieve this with configuration
> parameters. I have written a filter-module that understand start=
> argument and serve from proxy_cache cached files.
> But there is interesting case when the file does not exist in the
> cache (and there is start= as an argument) so then it should be
> downloaded through upstream from remote server and the file should not
> be cached, because it is partial.
>
> You told me the simplest way :) is there any other ways?
> I need just a direction ...
>
> Best wishes
> Toli
>
>
>
>
>
>
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://nginx.org/mailman/listinfo/nginx-devel
More information about the nginx-devel
mailing list