'How do I implement cache in my code with minimum change in my existing code?

I have the following structure.

application
├── session
    └── s_1.py
    └── s_2.py
    └── s_3.py
    └── s_4.py...

In each of the s_1,s_2,.. files we have a key and value pair like.

ID_1 = "Value_1"
ID_2 = "Value_2"
ID_3 = "Value_3
...

And these ID's are used all over the code.

Now we have decided to move the code to Google Cache and we will access it with the API. But the issue is that we need to change a lot in the code. Is there anything we could do that can result in a minimum change in the files.

My Solution:

I thought of creating a main class in session folder like:

Class Cache:
    def retrive(self,key):
        #Get value for cache
    def set(self,key):
        #Set value in cache

And using this class I will change all the s_1.py like

s_1

ID_1 = cache.retrive(ID_1)

But Since ID_1,ID_2 are all Global variables it won't be a good solution. Is there any other design possible to implement it.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source