codethesaur.us
codethesaur.us copied to clipboard
Feature/487-Use-django-caching-to-improve-TTFB
What GitHub issue does this PR apply to?
Resolves #487
What changed and why?
Use database caching per site for an hour using timeout of 3600 on non development environments that will use Dummy Caching (https://docs.djangoproject.com/en/4.1/topics/cache/#dummy-caching-for-development)
Site-wide cache will be stored in cache_table, to run this initially the command of python manage.py createcachetable
will need to be run after the deployment of this feature.
This uses the default django database caching settings with the schema of
CREATE TABLE IF NOT EXISTS "cache_table" (
"cache_key" varchar(255) NOT NULL PRIMARY KEY,
"value" text NOT NULL,
"expires" datetime NOT NULL
);
CREATE INDEX "cache_table_expires" ON "cache_table" ("expires");
Please see the following screenshot of the cache
Checklist
- [x] I claimed any associated issue(s) and they are not someone else's
- [x] I have looked at documentation to ensure I made any revisions correctly
- [x] I tested my changes locally to ensure they work
- [ ] (If editing Django) I have added or edited any appropriate unit tests for my changes
Any additional comments or things to be aware of while reviewing?
@geekygirlsarah Please let me know if that issue persists with the branch being out of date. I synced and pulled from the upstream on my fork before making this PR so it should be okay 🤔
I think this can work, but probably needs the migration to make it happen.
I think you can run
python manage.py makemigrations
and it should give you a new file to commit to create the database table for the cache.
I didn’t realize you could make the migrations like this, I will add it in when I get some time. Thanks! 🙏
I'm commenting that I see this update, but because this need more rigorous testing, I'll have to do it when I'm not out of town.
Hi @geekygirlsarah ,
I've tried adding the migrations by running the following commands. Am I missing something here?
I know the raw output to add the table is
CREATE TABLE IF NOT EXISTS "cache_table" (
"cache_key" varchar(255) NOT NULL PRIMARY KEY,
"value" text NOT NULL,
"expires" datetime NOT NULL
);
CREATE INDEX "cache_table_expires" ON "cache_table" ("expires");
Thanks!
@LittleBigProgramming I'm revisiting some stuff around here and was looking at your PR, and I can't seem to update it to pull in the latest updates and test it. I'll try to do it manually on my machine but you'll have to do it on your repo/branch.
@LittleBigProgramming I'm revisiting some stuff around here and was looking at your PR, and I can't seem to update it to pull in the latest updates and test it. I'll try to do it manually on my machine but you'll have to do it on your repo/branch.
Sorry I was on holiday, I can try and update the branch so you can test it!
@LittleBigProgramming I'm revisiting some stuff around here and was looking at your PR, and I can't seem to update it to pull in the latest updates and test it. I'll try to do it manually on my machine but you'll have to do it on your repo/branch.
Sorry I was on holiday, I can try and update the branch so you can test it!
@geekygirlsarah I have updated al the Github action checks seemed to pass okay! :eyes: