go-generics-cache
go-generics-cache copied to clipboard
Feature: Add save and load functions in cache
Hii !! It would be greate to have data persistance. I would like to contribute to add save and load feature. I am thinking of using gob to save / retreive data to / from file.
@alidevhere Thanks What do you think for the usage?
@Code-Hex I need to add graceful shutdown for my server. If my server restarts it should save whatever in cache and reload when started again. So if a make little fix and restart it doesnot affect other processes going on.
@alidevhere I see. sounds good.
I think that the development direction should be as follows:
- Create new options like
WithSave,WithRestore. WithSavemay have a functional parameter likefunc(cache Interface) {}and this function will be called received context.Done.WithRestoremay have a functional parameter likefunc(cache Interface) {}and this function will be initialized.
Is it possible to contribute in this way?
@Code-Hex Yeah sure!!
I have created a proof of concept pull request, I tried to Add Save and Load functions for cache. Let me share my findings with you:
- I used gob and gob needs Struct fields to be exported/public to encode and decode them.
- It is 100% working with simple cache. But for other algorithm caches we use datastructures like linked list etc. In these cases it is not as straight forward as for simple cache. We will have to do some manual work.
@Code-Hex I will do some more work on it with directions you gave.
Thanks
@alidevhere Thanks your initial PoC but I'm sorry I cannot accept the PR 🙏
@alidevhere Thanks your initial PoC but I'm sorry I cannot accept the PR 🙏
Yes, I made this PR just to show POC i will make a complete PR later