关于vue.js:如何查询缓存设置

5次阅读

共计 1567 个字符,预计需要花费 4 分钟才能阅读完成。

1) 验证服务器是否反对查问缓存

show variables like ‘%have_query_cache%’;

| Variable_name | Value |

| have_query_cache | YES |

2) 查问缓存会受到以下 3 个零碎变量值的影响

show variables like ‘query_cache%’;

| Variable_name | Value |

| query_cache_limit | 1048576 | // 可能缓存的最大后果集大小

| query_cache_min_res_unit | 4096 |

| query_cache_size | 1048576 | // 决定为查问缓存调配的内存大小

| query_cache_type | OFF | // 决定查问缓存的操作形式

| query_cache_wlock_invalidate | OFF |

那么 mysql 到底是怎么决定到底要不要把查问后果放到查问缓存中呢?是依据 query_cache_type 这个变量来决定的。

这个变量有三个取值:0,1,2,别离代表了 off、on、demand。

mysql 默认为开启 on (1)

如果是 0,那么 query cache 是敞开的。

如果是 1,那么查问总是先到查问缓存中查找,即便应用了 sql_no_cache 依然查问缓存,因为 sql_no_cache 只是不缓存查问后果,而不是不应用查问后果。

如果是 2,DEMAND 没有应用 sql_cache, 如同依然应用了查问手游缓存

论断:只有 query_cache_type 没有敞开,sql 查问总是会应用查问缓存,如果缓存没有命中则开始查问的执行打算到表中查问数据。

  1. sql_cahce 和 sql_no_cache hints 的应用

为了测试 sql 语句的效率,有时候要不必缓存来查问。

应用 SELECT SQL_NO_CACHE … 语法即可

SQL_NO_CACHE 的真正作用是禁止缓存查问后果,但并不意味着 cache 不作为后果返回给 query。

目前的 SQL_NO_CACHE 有两种解释:

1. 对以后 query 不应用数据库已有缓存来查问,则以后 query 破费工夫会多点

2. 对以后 query 的产生的后果集不缓存至零碎 query cache 里,则下次雷同 query 破费工夫会多点

sql_cache 意思是说,查问的时候应用缓存。

对 SQL_NO_CACHE 的解释及测试如下:

SQL_NO_CACHE means that the query 手游 www.diuxie.comresult is not cached. It does not meanthat the cache is not used to answer the query.

You may use RESET QUERY CACHE to remove all queries from the cache and then your next query should be slow again. Same effect if you change

the table, because this makes all cached queries invalid.

mysql> select count(*) from users where email = ‘hello’;

| count(*) |

| 0 |

1 row in set (7.22 sec)

mysql> select count(*) from users where email = ‘hello’;

| count(*) |

| 0 |

1 row in set (0.45 sec)

mysql> select count(*) from users where email = ‘hello’;

| count(*) |

| 0 |

1 row in set (0.45 sec)

mysql> select SQL_NO_CACHE count(*) from users where email = ‘hello’;

| count(*) |

| 0 |

1 row in set (0.43 sec)

正文完
 0