mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2024-11-17 06:19:24 +08:00
Fixed issue of not connecting to redis instance and added caching for courses
This commit is contained in:
parent
7053f1d487
commit
0215680ea5
4 changed files with 26 additions and 2 deletions
Binary file not shown.
|
@ -261,11 +261,30 @@ LEAFLET_CONFIG = {
|
||||||
'TILES': 'https://openstreetmap.keannu1.duckdns.org/tile/{z}/{x}/{y}.png'
|
'TILES': 'https://openstreetmap.keannu1.duckdns.org/tile/{z}/{x}/{y}.png'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
REDIS_HOST = os.getenv('REDIS_HOST', 'localhost')
|
||||||
|
REDIS_PORT = os.getenv('REDIS_PORT', 6379)
|
||||||
|
|
||||||
|
|
||||||
|
# Django Redis Cache
|
||||||
|
CACHES = {
|
||||||
|
"default": {
|
||||||
|
"BACKEND": "django_redis.cache.RedisCache",
|
||||||
|
"LOCATION": "redis://redis:6379/1",
|
||||||
|
"OPTIONS": {
|
||||||
|
"CLIENT_CLASS": "django_redis.client.DefaultClient",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
|
||||||
|
SESSION_CACHE_ALIAS = "default"
|
||||||
|
|
||||||
|
# Redis Cache for Django Channel Websockets
|
||||||
CHANNEL_LAYERS = {
|
CHANNEL_LAYERS = {
|
||||||
"default": {
|
"default": {
|
||||||
"BACKEND": "channels_redis.core.RedisChannelLayer",
|
"BACKEND": "channels_redis.core.RedisChannelLayer",
|
||||||
"CONFIG": {
|
"CONFIG": {
|
||||||
"hosts": [("127.0.0.1", 6379)],
|
"hosts": [("redis", 6379)],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
from django.utils.decorators import method_decorator
|
||||||
|
from django.views.decorators.cache import cache_page
|
||||||
from rest_framework import generics
|
from rest_framework import generics
|
||||||
from .models import Course
|
from .models import Course
|
||||||
from .serializers import CourseSerializer
|
from .serializers import CourseSerializer
|
||||||
|
@ -6,3 +8,7 @@ from .serializers import CourseSerializer
|
||||||
class CourseListView(generics.ListAPIView):
|
class CourseListView(generics.ListAPIView):
|
||||||
serializer_class = CourseSerializer
|
serializer_class = CourseSerializer
|
||||||
queryset = Course.objects.all()
|
queryset = Course.objects.all()
|
||||||
|
|
||||||
|
@method_decorator(cache_page(60*60))
|
||||||
|
def dispatch(self, *args, **kwargs):
|
||||||
|
return super().dispatch(*args, **kwargs)
|
||||||
|
|
|
@ -4,7 +4,6 @@ import redis
|
||||||
|
|
||||||
REDIS_HOST = os.getenv('REDIS_HOST', 'localhost')
|
REDIS_HOST = os.getenv('REDIS_HOST', 'localhost')
|
||||||
REDIS_PORT = os.getenv('REDIS_PORT', 6379)
|
REDIS_PORT = os.getenv('REDIS_PORT', 6379)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue