North-Seattle-College / ad440-winter2021-thursday-repo

NSC AD 440 Winter 2021 Thursday cohort practicum repo
Apache License 2.0
2 stars 27 forks source link

Switch for turning caching on/off for /users/{userid} #280

Open AllisonBC opened 3 years ago

AllisonBC commented 3 years ago

Closes #249 WHAT IT DOES: Feature switch to turn on and off caching for /users/{user_id}

TO TEST: Set up

  1. Be sure that you are able to use the VS Code debugger. Troubleshooting this alone was both difficult and time consuming.

  2. Install the Azure Cache extension in VS Code. image

  3. 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"

  4. Postman is helpful for making the requests.

Testing

  1. Run the debugger on Python Functions.

  2. In Postman or browser make a get request for user with id 1 Terminal: image VS Code Azure extension in Caches: (click on users:all) image

  3. 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.

  4. Run the debugger on Python Functions.

  5. In Postman or browser make a get request for user with id 10 Terminal: image

VS Code Azure extension in Caches: image

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.

TIME SPENT: Date Description Time
3/9 Meet with Johart 1.5 hrs
3/12 Review class lecture 1 hrs
3/12 Code Review and Development 2 hrs
3/15 Troubleshooting debugger issues 1 hrs
3/18 Debugging 1 hrs
3/5- 3/18 Record keeping 1 hrs
unicornsleuth commented 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

unicornsleuth commented 3 years ago

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!