Advantages and disadvantages of static variables to implement caching: Advantages: Fast, efficient and simple to implement. Because it is an internal variable of PHP, it is the most efficient among all caches. Disadvantages: It has poor flexibility, is only valid in this connection, has a small execution area, is only valid in the same function, and cannot operate across functions (global variables can be used instead). Summary: Static variables are very easy to use for caching and do not consume many resources. For those that need to query the database and may be executed multiple times in one connection, you might as well add it. Although the effect may be limited. |