Skip to content

Example of persistence with a DB or KV store #98

@viperfx

Description

@viperfx

Hi there,

It would be great to see an example implementation of how to modify the tokenCache to store in a simple DB/Cache system such as Redis.

def add(self, event, **kwargs):
super(SerializableTokenCache, self).add(event, **kwargs)
self.has_state_changed = True
def modify(self, credential_type, old_entry, new_key_value_pairs=None):
super(SerializableTokenCache, self).modify(
credential_type, old_entry, new_key_value_pairs)
self.has_state_changed = True
def deserialize(self, state):
# type: (Optional[str]) -> None
"""Deserialize the cache from a state previously obtained by serialize()"""
with self._lock:
self._cache = json.loads(state) if state else {}
self.has_state_changed = False # reset
def serialize(self):
# type: () -> str
"""Serialize the current cache state into a string."""
with self._lock:
self.has_state_changed = False
return json.dumps(self._cache, indent=4)

For a DB such as Redis:

  • What methods are most important to modify?
  • What is the structure of the cache? What is the key/value to store?

I also have a couple of other high-level questions:

  • Is there a cache value for each account? Does it make sense to store it in a place related to that user?
  • Is the cache value one big encrypted string that needs to be stored a cache system such as Redis and has no direct relation to an account?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Commited

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions