InTeGeR
InTeGeR

Reputation: 49

Cache for common MYSQL queries

Is there a way to handle the common Queries sent to MySQL to prevent unnecessary bandwidth usage ?

Upvotes: 1

Views: 55

Answers (1)

Robbie
Robbie

Reputation: 17720

Options are:

  1. Use MySQL to cache queries

    • Good: Fully automatic
    • Bad: Still requires trip to database server; Once the cache let me down in a project and took a long time to debug, but that was a long time ago...
  2. Cache locally using Memcached or Redis

    • Good: Faster (no trip to DB server). There are libraries that can handle it for you or you an "roll your own"
    • Bad: You need to install memcached or Redis, be careful what library you choose as some are inappropriate and difficult to handle. You need to handle expiry.

Another advantage of handling locally in memcached or Redis is that you can also store compiled/converted results. If you have lost of processing of results (e.g. turn it into an array with other validation and look-up) then you can cache that compiled result instead. But then you need to handle expiry/invalidating the cache which is easy, but requires discipline in your code.

Upvotes: 1

Related Questions