2
2
from datetime import datetime , timezone
3
3
4
4
from django .core .cache .backends .base import DEFAULT_TIMEOUT , BaseCache
5
+ from django .core .cache .backends .db import Options
5
6
from django .db import connections , router
6
7
from django .utils .functional import cached_property
7
8
from pymongo .errors import DuplicateKeyError
@@ -25,26 +26,11 @@ def loads(self, data):
25
26
return pickle .loads (data ) # noqa: S301
26
27
27
28
28
- class Options :
29
- """A class that will quack like a Django model _meta class.
30
-
31
- This allows cache operations to be controlled by the router
32
- """
33
-
34
- def __init__ (self , collection_name ):
35
- self .collection_name = collection_name
36
- self .app_label = "django_cache"
37
- self .model_name = "cacheentry"
38
- self .verbose_name = "cache entry"
39
- self .verbose_name_plural = "cache entries"
40
- self .object_name = "CacheEntry"
41
- self .abstract = False
42
- self .managed = True
43
- self .proxy = False
44
- self .swapped = False
29
+ class MongoDBCache (BaseCache ):
30
+ # This class uses collection provided by the database connection.
45
31
32
+ pickle_protocol = pickle .HIGHEST_PROTOCOL
46
33
47
- class BaseDatabaseCache (BaseCache ):
48
34
def __init__ (self , collection_name , params ):
49
35
super ().__init__ (params )
50
36
self ._collection_name = collection_name
@@ -54,12 +40,6 @@ class CacheEntry:
54
40
55
41
self .cache_model_class = CacheEntry
56
42
57
-
58
- class MongoDBCache (BaseDatabaseCache ):
59
- # This class uses collection provided by the database connection.
60
-
61
- pickle_protocol = pickle .HIGHEST_PROTOCOL
62
-
63
43
def create_indexes (self ):
64
44
self .collection .create_index ("expires_at" , expireAfterSeconds = 0 )
65
45
self .collection .create_index ("key" , unique = True )
0 commit comments