当前位置:网站首页>Relevant settings of wechat applet cache expiration time (recommended)
Relevant settings of wechat applet cache expiration time (recommended)
2022-07-01 23:58:00 【1024 questions】
Introduction to wechat applet caching mechanism
Which caches must expire
How to write it
Introduction to wechat applet caching mechanism Each wechat applet can have its own local cache , Can pass wx.setStorage(wx.setStorageSync)
、wx.getStorage(wx.getStorageSync)
、wx.clearStorage(wx.clearStorageSync)
You can set the local cache 、 Acquisition and cleanup .
However, wechat has set an infinite expiration time limit for the cache by default , This is for our small program development , It's very bad .
Which caches must expire I am developing a project , The user gets one through a third-party login token
, Every request must be accompanied by token
, however token
The time limit is 30 minute .
therefore token
It is necessary to treat it as a cache , But you must set the data of cache time limit .
After the user logs in successfully , Set the expiration time 、token Stored in the cache together :
// Set up token cache wx.setStorageSync('token', res.data.token);// current time var timestamp = Date.parse(new Date());// Add the expiration date var expiration = timestamp + 1200000; // cache 20 minute // Deposited in the cache wx.setStorageSync('data_expiration', expiration);
stay app.js
In the entry file , Whether the monitoring timed out :
// Whether the cache is out of date _isExpiration() { // current time var timestamp = Date.parse(new Date()); // Expiration time in cache var data_expiration = wx.getStorageSync("data_expiration"); // If it's not in the cache data_expiration, It doesn't mean token, Not signed in yet if (data_expiration) { // If I run out of time , Clear cache , Log back in if (timestamp > data_expiration) { wx.clearStorageSync(); return true; }else{ return false; } } return true; },
This is the end of this article about the relevant settings of wechat applet cache expiration time , For more information about the expiration time of wechat applet cache, please search the previous articles on SDN or continue to browse the relevant articles below. I hope you will support SDN more in the future !
边栏推荐
- Door level modeling - after class exercises
- How to solve the image pop-up problem when pycharm calls Matplotlib to draw
- Operate database transactions with jpatractionmanager
- SQL optimization
- [QT] QT cannot find a solution to the compiler using msvc2017
- 攻防演练复盘
- Windows10 install WSL (I) (wslregisterdistribution error)
- 电商RPA机器人,助力品牌电商抢立流量高点
- kubernetes资源对象介绍及常用命令(三)
- Graduation season is both a farewell and a new beginning
猜你喜欢
leetcode96不同的二叉搜索树
Overview of edge calculation
algolia 搜索需求,做的快自闭了...
第六章 数据流建模
Niuke - Practice 101 - reasoning clown
Algolia's search needs are almost closed
使用VB.net将PNG图片转成icon类型图标文件
Door level modeling - after class exercises
Selectively inhibiting learning bias for active sampling
深度学习 | 三个概念:Epoch, Batch, Iteration
随机推荐
- Oui. Env. Fichier XXX, avec constante, mais non spécifié
vue 强制清理浏览器缓存
UDS bootloader of s32kxxx bootloader
【C#】依赖注入及Autofac
Material Design组件 - 使用BottomSheet展现扩展内容(一)
Three methods of finding inverse numbers
Various global files related to [.Net core] program
ADO.NET之SqlDataAdpter对象
Shell process control
ADO. Net SqlConnection object usage summary
ERP项目施行计划的目的是什么?
Reproduction process and problems of analog transformer (ICLR 2022 Spotlight)
Li Kou today's question -241 Design priorities for operational expressions
关联性——组内相关系数
E-commerce RPA robot helps brand e-commerce to achieve high traffic
Material design component - use bottomsheet to show extended content (I)
MySQL: the difference between insert ignore, insert and replace
How to solve the image pop-up problem when pycharm calls Matplotlib to draw
algolia 搜索需求,做的快自闭了...
sql 优化