<commit_before>import datetime

from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.utils.timezone import utc
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext_lazy as _
from django.views.generic.detail import DetailView, BaseDetailView
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.views.generic.list import ListView
from django.contrib import messages
from django.views.decorators.http import condition
from django.core.cache import cache

from djgeojson.views import GeoJSONLayerView

from caminae.authent.decorators import path_manager_required, same_structure_required
from caminae.common.views import JSONResponseMixin, json_django_dumps, HttpJSONResponse
from .models import Path
from .forms import PathForm
from .filters import PathFilter
from . import graph as graph_lib


def latest_updated_path_date(*args, **kwargs):
    # TODO : generic for all models
    try:
        return Path.objects.latest("date_update").date_update
    except Path.DoesNotExist:
        dt = datetime.datetime(datetime.MAXYEAR, 12, 31)
        return dt.replace(tzinfo=utc)


class MapEntityLayer(GeoJSONLayerView):
    srid = settings.MAP_SRID

    @method_decorator(condition(last_modified_func=latest_updated_path_date))
    def dispatch(self, *args, **kwargs):
        return super(MapEntityLayer, self).dispatch(*args, **kwargs)
 
    def render_to_response(self, context, **response_kwargs):
        key = 'path_layer_json'
        result = cache.get(key)

        latest = latest_updated_path_date()

        if result:
            cache_latest, content = result<commit_msg>Caching: fix bug<commit_after>import datetime

from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.utils.timezone import utc
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext_lazy as _
from django.views.generic.detail import DetailView, BaseDetailView
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.views.generic.list import ListView
from django.contrib import messages
from django.views.decorators.http import condition
from django.core.cache import get_cache

from djgeojson.views import GeoJSONLayerView

from caminae.authent.decorators import path_manager_required, same_structure_required
from caminae.common.views import JSONResponseMixin, json_django_dumps, HttpJSONResponse
from .models import Path
from .forms import PathForm
from .filters import PathFilter
from . import graph as graph_lib


def latest_updated_path_date(*args, **kwargs):
    try:
        return Path.objects.latest("date_update").date_update
    except Path.DoesNotExist:
        return None


class MapEntityLayer(GeoJSONLayerView):
    srid = settings.MAP_SRID

    @method_decorator(condition(last_modified_func=latest_updated_path_date))
    def dispatch(self, *args, **kwargs):
        return super(MapEntityLayer, self).dispatch(*args, **kwargs)
 
    def render_to_response(self, context, **response_kwargs):
        cache = get_cache('fat')
        key = 'path_layer_json'

        result = cache.get(key)

        latest = latest_updated_path_date()

        if result and latest:
            cache_latest, content = result
{'fraction_non_alphanumeric': 0.07064083457526081, 'fraction_numerical': 0.0011922503725782414, 'mean_word_length': 4.726962457337884, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5484739', 'n_tokens_mistral': 943, 'n_tokens_neox': 918, 'n_words': 254}