Old thread: Cache for non-cookie users and fresh for cookie users
António P. P. Almeida
appa at perusio.net
Fri Feb 10 14:16:42 UTC 2012
On 10 Fev 2012 08h34 WET, quintinpar at gmail.com wrote:
> On Thu, Feb 9, 2012 at 2:19 PM, Maxim Dounin <mdounin at mdounin.ru>
> wrote:
>
>> Hello!
>>
>> On Thu, Feb 09, 2012 at 12:34:33PM +0530, Quintin Par wrote:
>>
>>> Picking up an old thread for caching
>>>
>>>
>> http://nginx.2469901.n2.nabble.com/Help-cache-or-not-by-cookie-td3124462.html
>>>
>>> Igor talks about caching by
>>>
>>> “No, currently the single way is:
>>>
>>> 1) add the cookie in proxy_cache_key
>>>
>>> proxy_cache_key "http://cacheserver$request_uri $cookie_name";
>>>
>>> 2) add "X-Accel-Expires: 0" in response with the cookie.”
>>>
>>> But from my understanding of “*X-Accel-Expires” *it expires the
>>> cache in the cache repository as given below
>>>
>>> “Sets when to expire the file in the internal Nginx cache, if one
>>> is
>> used.”
>>>
>>> Does this not mean that when I set cookie and pass
>>> “X-Accel-Expires: 0”
>> it
>>> expires the cache for the non logged in user too, for that cache
>>> key? A
>> new
>>> cache entry will then have to be created, right?
>>
>> No. X-Accel-Expires will prevent the particular response from
>> being cached, but won't delete existing cache entry.
>>
>
> So what should I do to delete a particular cache entry?
The easiest and fastest way is to delete the file. You need to build a
function in a programming language (PHP, Lua, Ruby) that computes the
key:
In PHP:
$filename = md5('example.com/foobar');
This is for a key like:
$host$request_uri
Then depending on the structure if your cache directory each directory
is named by taking a number of characters from the end of the string:
For the above:
$filename is 536d75ab92a8e8778916a971cb1fb4e0
If the cache dir structure is something like:
proxy_cache_path /var/cache/nginx/microcache levels=1:2 keys_zone=microcache:5M max_size=1G;
^^^
This means that the path to the file containing the cached page will
be:
/var/cache/nginx/microcache/0/4e/536d75ab92a8e8778916a971cb1fb4e0
where:
0 is substr($filename, -1, 1)
^
1 from levels=1:2
4e is substr($filename, -3, 2)
^
2 from levels=1:2
HTH,
--- appa
More information about the nginx
mailing list