<keep-alive> doesn't `destroy` cached components after when max is 1
See original GitHub issueVersion
2.6.10
Reproduction link
https://jsfiddle.net/p0te9vL3/
Steps to reproduce
- Open dev tools to see console
- Cycle through the routes
- View console and observe lifecycle hook logging
What is expected?
I’d expect once the max
cache is reached (in the example case of 1), the component that gets pruned also gets destroyed. In the documentation it states (emphasis mine):
max
The maximum number of component instances to cache. Once this number is reached, the cached component instance that was least recently accessed will be destroyed before creating a new instance.
What is actually happening?
The pruned component is never destroyed, it’s just removed from the cache. In the example, the beforeDestroy
hook is never called.
Related code: https://github.com/vuejs/vue/blob/636c9b4ef17f2062720b677cbbe613f146f4d4db/src/core/components/keep-alive.js#L37-L49
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:13 (5 by maintainers)
Top Results From Across the Web
How can I destroy a cached Vue component from keep-alive?
You can call this.$destroy() before user close the tab and delete all of data and event binding in that one.
Read more >Yes, this is how to cache pages by url with Vue, Vue Router ...
BONUS 1: You can use the max prop on the keep-alive component to limit the number of cached items. That would invalidate cache...
Read more >KeepAlive | Vue.js
<KeepAlive> is a built-in component that allows us to conditionally cache component instances when dynamically switching between multiple components.
Read more >records.config — Apache Traffic Server 9.1.4 documentation
After you modify records.config , run the command traffic_ctl config reload to ... Enabling keep-alive does not automatically enable purging of keep-alive ......
Read more >3 Tuning the GlassFish Server - Oracle Help Center
The EJB container caches and pools EJB components for better performance. ... After this time, the bean is destroyed if the bean in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
it will cache 1 component, so as soon as you switch the cache is occupied by the new component and the previous component is removed. A cache of one entry here is the same as not having any cache
It may cause other problem, such as last router will fresh when activated