Open AllisonBC opened 3 years ago
The key should be "users:{userId}" - don't use the universal key - that might be a leftover from other code. You want to build the key each time you cache, by passing in the userId, so you can make something this redis_key = "users:" + str(userId)
and use that to set/fetch the catch
Ok so I just saw that Johart's PR already went through with his CACHE_TOGGLE values as true/false, and then I just checked in Azure and it's been changed to true now, so I guess I was just out of the loop when that got changed and I'll have to make a PR to change my code. Disregard my comments on that note!
Closes #249 WHAT IT DOES: Feature switch to turn on and off caching for /users/{user_id}
TO TEST: Set up
Be sure that you are able to use the VS Code debugger. Troubleshooting this alone was both difficult and time consuming.
Install the Azure Cache extension in VS Code.
functions\local.settings.json
file set up: a. Need values: "ENV_DATABASE_CONNECTION_STRING", "ENV_REDIS_KEY", "ENV_REDIS_HOST", "ENV_REDIS_PORT" b. Add value:"CACHE_TOGGLE": "true"
Postman is helpful for making the requests.
Testing
Run the debugger on Python Functions.
In Postman or browser make a get request for user with id 1 Terminal: VS Code Azure extension in Caches: (click on users:all)
Return to
functions\local.settings.json
file, set"CACHE_TOGGLE": "false"
and save. NOTE: At this point, I had to exit and reopen VSCode entirely to get the debugger to acknowledge the change in this value.Run the debugger on Python Functions.
In Postman or browser make a get request for user with id 10 Terminal:
VS Code Azure extension in Caches:
Running this process a third time with the toggle set to "true" will result in a cache clear, and the user you requested being added to the cache.