from cachetools import LRUCache, cached
from neomodel import StructuredNode
# Setup cache
cache = LRUCache(maxsize=100) # Adjust size based on expected workload and available memory
class CachableStructuredNode(StructuredNode):
@classmethod
@cached(cache)
def get(cls, id):
return super(CachableStructuredNode, cls).get(id=id)
def save(self):
# Invalidate cache when the node is updated
cache.pop(self.id, None)
super(CachableStructuredNode, self).save()
def delete(self):
# Invalidate cache when the node is deleted
cache.pop(self.id, None)
super(CachableStructuredNode, self).delete()
Then, more complete solutions like redis or memcached could come later
General idea would be :
Then, more complete solutions like redis or memcached could come later