Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flask caching - Set permanent memory location of stored cache data #206

Open
Callum-Freeburn27 opened this issue Aug 20, 2021 · 0 comments

Comments

@Callum-Freeburn27
Copy link

I am trying to store a class instance that is created in one request and then accessed in other requests. As the first request will determine the criteria of the class object. I have tried to implement the cache flask module with the code below.

cache.init_app(app=app, config={"CACHE_TYPE": "simple",'CACHE_DIR': Path('/tmp')})

@app.route('/init/')
def init(env):
if env == "test":
cache.set("currentENV", service('chromedriver', service.test))
response.IsSuccess = True
elif env == "real":
cache.set("currentENV", service('chromedriver', service.real))
currentENV = cache.get("currentENV")
print(currentENV)
the class instance will then be accessed in another request as below

@app.route('/login//')
def login(MSISDN, password):
currentENV = cache.get("currentENV")
print(currentENV)
response = currentENV.login(MSISDN, password)
print(currentENV)
return json.loads(response.toJson())

However the problem is that is says the class instance is missing, I have printed the class instance out and it says that they are in differnet memory location. I am very unsure why this is happening. I believe this is the issue and If i can permanently set the memory location of the instance, it would solve my problem. Or if there another way to pass a class instance to differnet requests that would solve my problem as well

<Connect.service object at 0x7fc0a619a910>
127.0.0.1 - - [20/Aug/2021 15:41:42] "GET /login/user1/user1 HTTP/1.1" 200 -
<Connect.service object at 0x7fc0a619a370>
I have tried the solutions from both these pages and have had no luck.

Store large data or a service connection per Flask session

Are global variables thread-safe in Flask? How do I share data between requests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant