秒杀项目-多级缓存

秒杀项目

查询优化技术之多级缓存

多级缓存的定义

缓存设计

用快速存取设备、用内存
将缓存推到离用户最近的地方
脏缓存清理

redis缓存、本地缓存

单机版:
在这里插入图片描述
sentinal 哨兵模式
在这里插入图片描述
集群cluster模式
在这里插入图片描述
Redis集中式缓存商品详情页接入

Redis集中式缓存压测

类别 TPS 反应时间(毫秒) %CPU
redis集中式缓存 2000 245 2%

本地缓存

热点数据
脏读非常不敏感
内存可控

Guava cache
优点:
可控制的大小和超时时间
可配置的LRU策略
线程安全

本地缓存压测
线程数1000 、5秒发起、循环20次

类别 TPS 反应时间(毫秒) %CPU
Gvaua本地缓存 3500 38 2%

热点nginx lua缓存和proxy cache缓存

nginx proxy cache缓存
缓存的条件:
1、nginx反向代理前置
2、依靠文件系统存索引级的文件
3、依靠内存缓存文件地址

设置步骤;
在nginx.conf文件中
proxy_cache_path /usr/local/nginx/nginx/tmp_cache levels=1:2 keys_zone=tmp_cache:100m inactive=7d max_size=10g;
在这里插入图片描述
proxy_cache tmp_cache;
proxy_cache_key $uri;
proxy_cache_valid 200 206 304 302 7d;
在这里插入图片描述
nginx proxy cache缓存压测
线程数1000 、5秒发起、循环20次

类别 TPS 反应时间(毫秒) %CPU
本地缓存 2800 245 2%

效果不好。

nginx lua缓存

lua协程机制
协程:线程空间栈里的一个执行单元,有独立的运行空间,基于用户态模拟出来,本身依托于线程,被CPU执行
1、依附于线程的内存模型,切换开销小
2、遇阻塞即归还执行权,代码同步

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Vue-element-admin 是基于 Vue.js 和 Element UI 实现的后台管理系统框架。它采用了 Vue Router 实现路由跳转和页面切换。在 Vue-element-admin 中,实现多级路由缓存可以通过以下步骤: 1. 在路由配置文件中,设置需要缓存的路由组件的 meta 属性中添加 keepAlive: true。 ``` const routes = [ { path: '/', component: Layout, redirect: '/dashboard', children: [ { path: 'dashboard', component: () => import('@/views/dashboard/index'), name: 'Dashboard', meta: { title: 'Dashboard', icon: 'dashboard', keepAlive: true } } ] } ] ``` 2. 在 App.vue 文件中,添加 keep-alive 组件,并设置 include 属性为需要缓存的路由组件的名称。 ``` <template> <div id="app"> <keep-alive :include="cachedViews"> <router-view /> </keep-alive> </div> </template> <script> export default { name: 'App', computed: { cachedViews() { return this.$store.state.tagsView.cachedViews } } } </script> ``` 3. 在 store 文件夹中创建 tagsView.js 文件,设置需要缓存的路由组件的名称和缓存状态。 ``` const state = { cachedViews: [] } const mutations = { ADD_CACHED_VIEW: (state, view) => { if (state.cachedViews.includes(view.name)) return if (!view.meta.keepAlive) return state.cachedViews.push(view.name) }, DEL_CACHED_VIEW: (state, view) => { const index = state.cachedViews.indexOf(view.name) if (index > -1) { state.cachedViews.splice(index, 1) } } } const actions = { addCachedView({ commit }, view) { commit('ADD_CACHED_VIEW', view) }, delCachedView({ commit }, view) { commit('DEL_CACHED_VIEW', view) } } export default { namespaced: true, state, mutations, actions } ``` 这样就可以实现多级路由缓存了。需要注意的是,路由组件的名称必须是唯一的,否则可能会出现缓存错误。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值