When to use cache system in PHP?

4

I've been reading a bit about using the cache in PHP, its advantages and disadvantages. Some doubts have arisen and so on.

If I have a system that only shows texts with update (re-editing) of the same, very small, is it advisable to use CACHE? If so, which one should I use and how?

    
asked by anonymous 09.06.2014 / 23:13

2 answers

4

Cache is somewhat abstract, there are several optimizations you can do on a system that fit well into this word, such as:

  • Static page cache
  • Database query cache
  • Service replies cache
  • Opcodes cache

I think in most cases, so much concern for optimization is unnecessary, although some are part of good programming practice.

It all depends on the load on your system. If you're having performance issues (lots of bandwidth usage, processing, memory, disk space, etc.), start optimizing your system from the simplest to the most complicated ones.

There are some generic tips and easy to implement such as:

  • Always watch out for the two biggest performance villains: network access and disk access.
  • Some techniques such as caching static files in the client browser using headers can alleviate your problems with bandwidth usage.
  • Importing common libraries of third party CDNs can also help with bandwidth (Example: link )
  • Avoiding the use of SELECT * or adopting ARCHIVE or MEMORY tables on a MySQL-based system can expedite queries.

And so on ...

    
22.06.2014 / 03:35
2

Yes, you should use it.

In PHP, for simple use, such as a website that runs on a single machine, use the APC, preferably by passing through an object that manages read and write, such as the ZF2 Cache Component. / p>

Each of your text must be a single id that will identify cache (ex: texto_id_776482 . When you first display 776482 text, it checks whether it is already cached, and if it does, it displays it from the APC retrieved, or else displays and writes to the APC what it received from the database.

    
22.07.2014 / 13:58