Comments (4)
Hey!
I understand it may be confusing, but this is actually explained in the Eviction configuration section – Nebulex.Adapters.Local. Perhaps the docs can be improved, but I think it should help to understand.
Is ttl always required?
No, it is not, this is an option that is optional.
What happens if it is not set?
The :ttl
option is supposed to be a global or shared option across the adapters, therefore, it will depend on the adapter also. However, for the Nebulex.Adapters.Local
adapter which is the one I suppose you're interested in. Let me first explain what happens when the option :ttl
is set. When :ttl
is set, every time the key is accessed, the local adapter checks the TTL, and if it has expired, it removed the key from the cache at that moment, which means, it is evaluated on-demand every time the key is accessed or fetched. So, when it is not set, the adapter doesn't check the TTL for that key. Also, when it is not set, for the eviction you basically depend completely on the generation manager, which runs every X period of time given by :gc_interval
option. When :gc_interval
occurs, a new generation is created, evicting the keys in the older one (releasing memory space). Since it is a generation cache, this process ensures the evicted keys are the least frequently used.
What if it is longer than the gc_interval?
I think this is explained in the link I shared above, there is a section about the :ttl
option. But to give a quick answer, when the :ttl
is longer than the :gc_interval
, there may be a situation where the GC runs removing the older generation and a key previously set with a TTL is removed, even it the TTL hasn't happened yet. Overall, the :gc_interval
has precedence over the :ttl
(you can find more info in the link I shared).
Let me know if this addresses your inquiries, I stay tuned. Thanks!
from nebulex.
Hey,
Thanks a lot!
I am using the partitioned adapter.
So if I understand correctly, if I don't set a ttl and :gc_interval
passes only items that have not been accessed in the period are removed? Or in the last 2 period (generation)?
If an item is accessed they are kept around forever?
But if they have ttl they are removed when accessed next time and the ttl is over?
from nebulex.
So if I understand correctly, if I don't set a ttl and :gc_interval passes only items that have not been accessed in the period are removed? Or in the last 2 period (generation)?
In the 2nd period (after 2 generations are pushed). To give an example, suppose your cache start, then there will be just one generation, and items start getting accessed. Then :gc_interval
runs and a new generation is created, at this time you have 2 generations, the new one starting empty and the older one. Then in the next :gc_interval
cycle, a new generation is created and is set as the new one, the previously new one goes to be the older one, and the previously older one is deleted. The next cycle is the same. As you said, an item stored in the newest generation will be evicted after 2 cycles (two GC runs), the first one goes to the older generation, and the next one is removed. So, when an item or key is continuously hit, it will be kept in the newest generation all the time, well, as long as it keeps being hit.
If an item is accessed they are kept around forever?
Sort of, if the item or key is continuously hit, which is, it is accessed at least once before the 2nd cycle runs, the key will be always around.
But if they have ttl they are removed when accessed next time and the ttl is over?
That is correct!
from nebulex.
Thanks for the clarification!
from nebulex.
Related Issues (20)
- Docs on Migrating to v2 from Nebulex.Adapters.Dist.Cluster HOT 5
- `Nebulex.Cache` callbacks mention "Shared Options" section that do not exist
- Support for functions that can set TTL in Decorator similar to Match HOT 9
- Where to use load/2, dump/2 HOT 4
- random :erpc, :timeout with partitioned get HOT 2
- Is there any way to get the size of the cache? HOT 4
- Seeing Nebulex.RPCError during deployments with partitioned adapter HOT 4
- Nebulex.RegistryLookupError HOT 9
- Replicated adapter syncing during rolling deployment HOT 5
- Bug on Local adapter when using `delete_all` and keys are nested tuples: not a valid match specification HOT 3
- is allocated_memory param global on per node when using Nebulex.Adapters.Partitioned with :shards HOT 2
- Dangling reference on `cache_evict` when using referenced keys HOT 4
- Regression on decorated functions and Elixir 1.16 HOT 3
- Empty arguments list passed to `generate/3` in Elixir 1.16 HOT 3
- `Multilevel` inclusive cache doesn't duplicate entries backwards on `get_all/2` HOT 3
- Fix compatibility with Elixir 1.15 and 1.16 HOT 3
- Support cache refreshing in the background HOT 1
- Having a cache per user ID... HOT 4
- 2.6.2 is missing from tags and releases on github HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nebulex.