Some sql runtime is time-consuming, consumes system resources, and cannot be further optimized, and each time the data is obtained, it does not change much.
Then the information obtained by this sql statement will be cached for the next execution
This saves system resources very much
View query cache size
mysql> select * from t_user_auth where real_name like '%zanyuiiy%';
Empty set (1.58 sec)
mysql> select * from t_user_auth where real_name like '%zanyuiiy%';
Empty set (1.64 sec)
mysql> show variables like 'query_%';
+------------------------------+----------+
| Variable_name | Value |
+------------------------------+----------+
| query_alloc_block_size | 8192 |
| query_cache_limit | 1048576 |
| query_cache_min_res_unit | 4096 |
| query_cache_size | 67108864 |
| query_cache_type | OFF |
| query_cache_wlock_invalidate | OFF |
| query_prealloc_size | 8192 |
+------------------------------+----------+
7 rows in set (0.00 sec)
mysql> set global query_cache_size=64*1024*1024;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> set global query_cache_size=0;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> show variables like 'query_%';
+------------------------------+---------+
| Variable_name | Value |
+------------------------------+---------+
| query_alloc_block_size | 8192 |
| query_cache_limit | 1048576 |
| query_cache_min_res_unit | 4096 |
| query_cache_size | 0 |
| query_cache_type | OFF |
| query_cache_wlock_invalidate | OFF |
| query_prealloc_size | 8192 |
+------------------------------+---------+
7 rows in set (0.00 sec)
mysql> select * from t_user_auth where real_name like '%zanyuiiy%';
Empty set (1.77 sec)
mysql> select * from t_user_auth where real_name like '%zanyuiiy%';
Empty set (1.59 sec)
mysql> select * from t_user_auth where real_name like '%zanyuiiy%';
Empty set (1.60 sec)
mysql> select * from t_user_auth where real_name like '%zanyuiiy%';
Empty set (1.63 sec)
mysql> set global query_cache_size=64*1024*1024;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> select * from t_user_auth where real_name like '%zanyuiiy%';
Empty set (1.58 sec)
mysql> select * from t_user_auth where real_name like '%zanyuiiy%';
Empty set (1.58 sec)
mysql> select * from t_user_auth where real_name like '%zanyuiiy%';
Empty set (1.61 sec)
mysql>
Cache invalidation
If the data of the data table changes, or the structure of the data table changes, the cache becomes invalid.
What does not apply to caching
The data obtained by sql statement changes every time