When to use cache system in PHP?

Asked

Viewed 1,064 times

4

I’ve been reading a little about the use of PHP cache, its advantages and disadvantages. Some questions and etc.

If I have a system that only shows updated texts (rewrites) of the same, very small, is it advisable to use CACHE? If yes, which one should use and how?

  • 1

    I think the question applies to any platform, not just PHP.

2 answers

5

Cache is kind of abstract, there are several optimizations you can do on a system that fit well into that word, like:

  • Cache of static pages
  • Cache of database queries
  • Cache of service responses
  • Cache of opcodes

I find that in most cases, so much concern with optimization is unnecessary, although some are part of good programming practices.

It all depends on the load of your system. If you are experiencing performance problems (too much bandwidth, processing, memory, disk space, etc.), start doing system optimizations from the simplest to the most complicated.

There are some generic and quite easy to implement tips like:

  • Always stay tuned for the two biggest performance villains: network access and disk access.
  • Some techniques like caching static files in the client’s browser using headers can alleviate your bandwidth issues.
  • Importing common third-party CDN libraries can also help a little with bandwidth (example: https://developers.google.com/speed/libraries/devguide)
  • Avoid the use of SELECT * or adopt ARCHIVE or MEMORY tables in a Mysql-based system can expedite queries.

And so on and so on...

  • I think "middle" is humility. Cache is something, in fact, abstract. Other than that, +1. ;)

2

Yes, you must use.

In PHP, for simple use, as a website that runs on a single machine, use APC, preferably passing through an object of yours that manages reading and writing, such as the ZF2 Cache Component.

Every text of yours should be one id which will identify the cache (ex: texto_id_776482. The moment you first display the text 776482, checks if it is already cached and if yes, displays it from what it recovered from APC or, if not, displays and writes to APC what it received from the database.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.