Skip to content

Commit

Permalink
added cache
Browse files Browse the repository at this point in the history
  • Loading branch information
two-trick-pony-NL committed May 19, 2023
1 parent 31a8c3b commit a0bb8ca
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions AWS/deploymentconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
"nginx": {
"image": ":tldrnews.nginx.latest",
"ports": {"80": "HTTP"}
},
"redis-cache": {
"image": "redis/redis-stack:latest",
"ports": {"6379": "HTTP", "8001":"HTTP"}
}
}
4 changes: 4 additions & 0 deletions articles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
from .models import Article
from newssources.models import Source
from django.contrib.auth.decorators import login_required
from django.views.decorators.cache import cache_page




# Create your views here.
@cache_page(60 * 15)
def article_by_slug(request, slug):
article = Article.objects.filter(slug=slug).last()
sources = article.sources.all()
context = {'article':article, 'sources':sources}
return render(request, "article_index.html", context)

@cache_page(60 * 15)
def article_by_id(request, id):
article = Article.objects.get(id=id)
sources = article.sources.all()
Expand Down
7 changes: 7 additions & 0 deletions core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@
},
}}

#Setting location of cache server (Redis in our case)
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.redis.RedisCache",
"LOCATION": "redis://127.0.0.1:6379",
}
}

# Password validation
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators
Expand Down
6 changes: 6 additions & 0 deletions homepage/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from django.shortcuts import render
from articles.models import Article
from django.db.models import Count
from django.views.decorators.cache import cache_page


# Create your views here.
@cache_page(60 * 15)
def index(request):
articles = Article.objects.filter(published=True, created_by_ai=True).order_by('-sources')
#articles = Article.objects.annotate(most_sources=Count("sources")).order_by("most_sources")
Expand All @@ -13,14 +16,17 @@ def index(request):
context = {'hero':hero, 'highlighted':highlighted, 'frontpage':frontpage, 'older':older}
return render(request, "homepage.html", context)

@cache_page(60 * 15)
def faq(request):
context = {}
return render(request, "faq_index.html", context)

@cache_page(60 * 15)
def funding(request):
context = {}
return render(request, "funding_index.html", context)

@cache_page(60 * 15)
def responsibleai(request):
context = {}
return render(request, "ai_index.html", context)
6 changes: 3 additions & 3 deletions machinelearning/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

if ENABLE_AI:
print(ENABLE_AI)
import numpy as np
from sentence_transformers import SentenceTransformer
sentencemodel = SentenceTransformer('sentence-transformers/all-mpnet-base-v1')
#import numpy as np
#from sentence_transformers import SentenceTransformer
#sentencemodel = SentenceTransformer('sentence-transformers/all-mpnet-base-v1')
else:
pass

Expand Down

0 comments on commit a0bb8ca

Please sign in to comment.