-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #250 from norcalipa/norcalipa/view-caching-2
Adding additional caching, moving cache TTL to ENV
- Loading branch information
Showing
9 changed files
with
71 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ DB_USER=crank | |
DB_PORT=3306 | ||
PYTHON_UNBUFFERED=1 | ||
REDIS_URL=redis://redis:6379/0 | ||
CACHE_TTL=60 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright (c) 2024 Isaac Adams | ||
# Licensed under the MIT License. See LICENSE file in the project root for full license information. | ||
from django import template | ||
from django.core.cache import cache | ||
from allauth.socialaccount.models import SocialApp | ||
from django.conf import settings | ||
|
||
register = template.Library() | ||
|
||
@register.simple_tag | ||
def get_cached_social_app(provider): | ||
cache_key = f'social_app_{provider}' | ||
social_app = cache.get(cache_key) | ||
if not social_app: | ||
social_app = SocialApp.objects.filter(provider=provider).first() | ||
cache.set(cache_key, social_app, timeout=settings.CACHE_MIDDLEWARE_SECONDS) | ||
return social_app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters