Drop cache.

This commit is contained in:
Julien Palard 2023-04-21 09:24:26 +02:00
parent c1826083fb
commit d343022348
Signed by: mdk
GPG Key ID: 0EFC1AC1006886F8
2 changed files with 3 additions and 31 deletions

View File

@ -4,19 +4,13 @@ from django.template import loader
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter
from paste.tools import cache_exists, cache_fetch, cache_store
def render_pygments(request, paste, data):
"""Renders Pygments template."""
key = paste.slug + "_pygments.cache"
if cache_exists(key):
highlighted_content = cache_fetch(key)
else:
lexer = get_lexer_by_name(paste.language.slug)
formatter = HtmlFormatter(style="emacs")
highlighted_content = highlight(paste.content, lexer, formatter)
cache_store(key, highlighted_content)
lexer = get_lexer_by_name(paste.language.slug)
formatter = HtmlFormatter(style="emacs")
highlighted_content = highlight(paste.content, lexer, formatter)
data["paste"] = paste
data["highlighted"] = highlighted_content
rendered = loader.render_to_string("paste/show-pygments.html", data, request)

View File

@ -22,25 +22,3 @@ def random_id(model):
if not model.objects.filter(slug=potential_uuid):
return potential_uuid
return uuid
def cache_get_filepath(key):
"""Returns cache path."""
return os.path.join(settings.CACHE_PATH, key)
def cache_exists(key):
"""Says if cache exists for key."""
return os.path.isfile(cache_get_filepath(key))
def cache_store(key, value):
"""Store cache value for key."""
with open(cache_get_filepath(key), "w") as cache_file:
cache_file.write(value)
def cache_fetch(key):
"""Fetch cache value for key."""
with open(cache_get_filepath(key), "r") as cache_file:
return cache_file.read()