How does Nginx look-up cached resource?
mdounin at mdounin.ru
Fri Sep 4 13:23:30 UTC 2015
On Thu, Sep 03, 2015 at 06:39:49PM -0700, Shuxin Yang wrote:
> I'm Nginx newbie. I have a question regarding how nginx lookup a cached
> As far as I can tell, given a cache-key k. Nginx uses crc32(k) as as the
> key to lookup
> the cached resource in a RB tree, and use md5(k) verify if conflict take
> place; the
> key k per se is not used for looking up resource. Is my understanding
No, vice versa.
MD5 is used to identify a resource, and CRC32 is used to
additionally verify if there are any collisions. If any collision
is detected, nginx will complain loudly.
As of now, the only case when the message about a collision was
seen, it was the result of a bug, not a collision.
> If so, how can we guarantee that crc32 and md5 combined can uniquely
> identify a resource?
We can't. Collisions are unavoidable if you use a hash function
with more inputs than outputs. The question is how often
collisions are observed in practice.
More information about the nginx-devel