Skip to content

Convert cache to json and vice versa #2

Description

@AmosSzust

Hi

What about adding support for converting the cache to json and vice versa? This way I can save/load it to/from a file for when the server restarts.

convertCacheToJson(): string {
    const json = Object.fromEntries(this.itemKeyToItemValueWrapperMap);
    return JSON.stringify(json);
}

convertJsonToCach(json: string): number {
    const tempMap = new Map(Object.entries(JSON.parse(json)));
    this.clear();    
    for (const entry of tempMap.entries()) {      
      this.itemKeyToItemValueWrapperMap.set(...);
    }
    return this.getItemCount();
}

I saw that itemKeyToItemValueWrapperMap is readOnly and I didn't want to break your code/pattern so I was thinking of using a temporary map but got lost in the middle. What do you think?
Thanks

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions