0

I am in the process of implementing a cache system for a series of apps that access an external (as not under our control) API via XML queries. The API is slowing down during peak hours and we have a number of clients that complained about this.

I plan on using Symfony/Cache with the filesystem adapter (and later with Redis). The approach I want to take is to store a hash of the query as the Cache Item Key, and the API response as the cache value.

So every time a user tries to make a call to the API, the app will generate the hash of the query and search for it in the cache. If there's a hit (found and not expired) it will return the cached response, otherwise it will call the API and store the response in the cache.

What hashing algorithm should I use in order to not have any collisions (we don't want the client to get the wrong response) and also be fast enough?

Răzvan
  • 981
  • 9
  • 20
  • `What hashing algorithm should I use in order to not have any collisions` That is impossible to achieve (unless of course, you use at least same amount of bits that quereies need to store hash). You can however reduce the probability as much as you'd like by increasing the fingerpring (/hash) value. – amit Mar 18 '17 at 07:29
  • SHA256 is pretty good - the probability of collision is very low. Here is a detailed answer: http://stackoverflow.com/questions/4014090/is-it-safe-to-ignore-the-possibility-of-sha-collisions-in-practice – katona.abel Apr 26 '17 at 08:33

0 Answers0