From f0112b8d6581f736fc06d88159974f5084470f17 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste <bleme@pm.me> Date: Fri, 9 Oct 2020 12:30:24 +0200 Subject: [PATCH] syntax: Add settings parameter to activate cache on permissions --- README.md | 2 ++ djangoldp/permissions.py | 3 ++- djangoldp/tests/settings_default.py | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 94f9d291..3fe81ecc 100644 --- a/README.md +++ b/README.md @@ -126,12 +126,14 @@ LDP_RDF_CONTEXT = 'https://cdn.happy-dev.fr/owl/hdcontext.jsonld' DJANGOLDP_PACKAGES = [] SITE_URL = 'http://localhost:8000' BASE_URL = SITE_URL +PERMISSIONS_CACHE = True ``` * `LDP_RDF_CONTEXT` tells DjangoLDP where our RDF [ontology](https://www.w3.org/standards/semanticweb/ontology) is defined, which will be returned as part of our views in the 'context' field. This is a web URL and you can visit the value to view the full ontology online. The ontology can be a string, as in the example, but it can also be a dictionary, or a list of ontologies (see the [JSON-LD spec](https://json-ld.org) for examples) * `DJANGOLDP_PACKAGES` defines which other [DjangoLDP packages](https://git.happy-dev.fr/startinblox/djangoldp-packages) we're using in this installation * `SITE_URL` is the URL serving the site, e.g. `https://example.com/`. Note that if you include the DjangoLDP urls in a nested path (e.g. `https://example.com/api/`), then `SITE_URL` will need to be set to this value * `BASE_URL` may be different from SITE_URL, e.g. `https://example.com/app/` +* `PERMISSIONS_CACHE` Activate cache on Permissions (Set to True Recommended) 4. You can also register your model for the django administration site diff --git a/djangoldp/permissions.py b/djangoldp/permissions.py index 55598b66..706d0df7 100644 --- a/djangoldp/permissions.py +++ b/djangoldp/permissions.py @@ -1,4 +1,5 @@ import time +from django.conf import settings from django.contrib.auth.models import _user_get_all_permissions from django.core.exceptions import PermissionDenied from django.db.models.base import ModelBase @@ -19,7 +20,7 @@ class LDPPermissions(DjangoObjectPermissions): perms_cache = { 'time': time.time() } - with_cache = True + with_cache = settings.PERMISSIONS_CACHE @classmethod def invalidate_cache(cls): diff --git a/djangoldp/tests/settings_default.py b/djangoldp/tests/settings_default.py index 3686e777..7c7cb1b2 100644 --- a/djangoldp/tests/settings_default.py +++ b/djangoldp/tests/settings_default.py @@ -93,3 +93,4 @@ LDP_RDF_CONTEXT={ } SEND_BACKLINKS=False GUARDIAN_AUTO_PREFETCH = True +PERMISSIONS_CACHE = True -- GitLab