22from datetime import datetime , timezone
33
44from django .core .cache .backends .base import DEFAULT_TIMEOUT , BaseCache
5+ from django .core .cache .backends .db import Options
56from django .db import connections , router
67from django .utils .functional import cached_property
78from pymongo .errors import DuplicateKeyError
@@ -25,26 +26,11 @@ def loads(self, data):
2526 return pickle .loads (data ) # noqa: S301
2627
2728
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.
4531
32+ pickle_protocol = pickle .HIGHEST_PROTOCOL
4633
47- class BaseDatabaseCache (BaseCache ):
4834 def __init__ (self , collection_name , params ):
4935 super ().__init__ (params )
5036 self ._collection_name = collection_name
@@ -54,12 +40,6 @@ class CacheEntry:
5440
5541 self .cache_model_class = CacheEntry
5642
57-
58- class MongoDBCache (BaseDatabaseCache ):
59- # This class uses collection provided by the database connection.
60-
61- pickle_protocol = pickle .HIGHEST_PROTOCOL
62-
6343 def create_indexes (self ):
6444 self .collection .create_index ("expires_at" , expireAfterSeconds = 0 )
6545 self .collection .create_index ("key" , unique = True )
0 commit comments