File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 13
13
14
14
from .mixins import (
15
15
ConfigDefaultTypesMixin ,
16
+ TBaseCacheBackend ,
16
17
TEventHandler ,
17
18
TExceptionHandler ,
18
19
TMiddleware ,
@@ -120,6 +121,7 @@ class Config:
120
121
TEMPLATE_GLOBAL_FILTERS : t .Dict [str , t .Callable [..., t .Any ]] = {}
121
122
122
123
LOGGING : t .Optional [t .Dict [str , t .Any ]] = None
124
+ CACHES : t .Dict [str , TBaseCacheBackend ] = {}
123
125
124
126
@validator ("MIDDLEWARE" , pre = True )
125
127
def pre_middleware_validate (cls , value : t .Any ) -> t .Any :
@@ -137,3 +139,9 @@ def serializer_custom_encoder(cls, value: t.Any) -> t.Any:
137
139
def pre_static_mount_path (cls , value : t .Any ) -> t .Any :
138
140
assert value .startswith ("/" ), "Routed paths must start with '/'"
139
141
return value
142
+
143
+ @validator ("CACHES" , pre = True )
144
+ def pre_cache_validate (cls , value : t .Dict ) -> t .Any :
145
+ if value and not value .get ("default" ):
146
+ raise ValueError ("CACHES configuration must have a 'default' key" )
147
+ return value
Original file line number Diff line number Diff line change 4
4
from starlette .responses import JSONResponse
5
5
from starlette .types import ASGIApp
6
6
7
+ from ellar .cache .model import BaseCacheBackend
7
8
from ellar .constants import LOG_LEVELS as log_levels
8
9
from ellar .core .events import EventHandler
9
10
from ellar .core .exceptions .interfaces import IExceptionHandler
19
20
"TMiddleware" ,
20
21
"TEventHandler" ,
21
22
"TExceptionHandler" ,
23
+ "TBaseCacheBackend" ,
22
24
]
23
25
24
26
27
+ class TBaseCacheBackend :
28
+ @classmethod
29
+ def __get_validators__ (
30
+ cls : t .Type ["TBaseCacheBackend" ],
31
+ ) -> t .Iterable [t .Callable [..., t .Any ]]:
32
+ yield cls .validate
33
+
34
+ @classmethod
35
+ def validate (cls : t .Type ["TBaseCacheBackend" ], v : t .Any ) -> t .Any :
36
+ if isinstance (v , BaseCacheBackend ):
37
+ return v
38
+
39
+ raise ValueError (f"Expected BaseCacheBackend, received: { type (v )} " )
40
+
41
+
25
42
class TExceptionHandler :
26
43
@classmethod
27
44
def __get_validators__ (
@@ -162,3 +179,5 @@ class ConfigDefaultTypesMixin:
162
179
# TrustHostMiddleware setup
163
180
ALLOWED_HOSTS : t .List [str ]
164
181
REDIRECT_HOST : bool
182
+
183
+ CACHES : t .Dict [str , TBaseCacheBackend ]
You can’t perform that action at this time.
0 commit comments