mateenbagheri / memorabilia

Apache License 2.0
0 stars 0 forks source link

Implement TTL feature for SET command #9

Open mateenbagheri opened 1 month ago

mateenbagheri commented 1 month ago

User must be able to set a TTL (time to live) value for values while setting them. The initial idea for how this is going to be implemented is that we are going to have two methods for detecting expiration. First method: we check if the TTL and if it has passed while user is retrieving data. This helps us worry less about continuously checking whether the TTL time has passed or not. If TTL has passed, we are going to delete and drop the value. This has a problem however. If user keeps setting values in a rapid pace without reading them, we can have our memory filled with invalid data that are yet waiting to be detected. Here is where the second method comes in handy. Second method: We have a cronjob with preset time interval that checks for TTL expiration and deletes the keys if they are expired. Doing this in an interval helps us avoid the problem mentioned in first section while not taking our computational power all the time.