@@ -53,7 +53,7 @@ def __init__(self, l1_capacity: int = 1000, l2_capacity: int = 10000):
5353 self .l2_capacity = l2_capacity
5454
5555 # L1 Memory Lock (LFU implementation)
56- self .l1_lock : Dict [str , LFUNode ] = {}
56+ self .l1_cache : Dict [str , LFUNode ] = {}
5757 self .freq_map : Dict [int , LFUDoublyLinkedList ] = {}
5858 self .min_freq = 0
5959 self .l1_lock = threading .RLock ()
@@ -83,8 +83,8 @@ def _update_freq(self, node: LFUNode):
8383
8484 def get (self , key : str ) -> Optional [Any ]:
8585 with self .l1_lock :
86- if key in self .l1_lock :
87- node = self .l1_lock [key ]
86+ if key in self .l1_cache :
87+ node = self .l1_cache [key ]
8888 self ._update_freq (node )
8989 logger .debug ("L1 Lock HIT for key: %s" , key )
9090 return node .value
@@ -106,28 +106,28 @@ def get(self, key: str) -> Optional[Any]:
106106
107107 def _promote_to_l1 (self , key : str , value : Any ):
108108 with self .l1_lock :
109- if len (self .l1_lock ) >= self .l1_capacity :
109+ if len (self .l1_cache ) >= self .l1_capacity :
110110 self ._evict_l1 ()
111111
112112 node = LFUNode (key , value , 1 )
113- self .l1_lock [key ] = node
113+ self .l1_cache [key ] = node
114114 if 1 not in self .freq_map :
115115 self .freq_map [1 ] = LFUDoublyLinkedList ()
116116 self .freq_map [1 ].insert_at_head (node )
117117 self .min_freq = 1
118118
119119 def put (self , key : str , value : Any ):
120120 with self .l1_lock :
121- if key in self .l1_lock :
122- node = self .l1_lock [key ]
121+ if key in self .l1_cache :
122+ node = self .l1_cache [key ]
123123 node .value = value
124124 self ._update_freq (node )
125125 else :
126- if len (self .l1_lock ) >= self .l1_capacity :
126+ if len (self .l1_cache ) >= self .l1_capacity :
127127 self ._evict_l1 ()
128128
129129 node = LFUNode (key , value , 1 )
130- self .l1_lock [key ] = node
130+ self .l1_cache [key ] = node
131131 if 1 not in self .freq_map :
132132 self .freq_map [1 ] = LFUDoublyLinkedList ()
133133 self .freq_map [1 ].insert_at_head (node )
@@ -140,7 +140,7 @@ def _evict_l1(self):
140140 if self .min_freq in self .freq_map :
141141 evicted_node = self .freq_map [self .min_freq ].remove_tail ()
142142 if evicted_node :
143- del self .l1_lock [evicted_node .key ]
143+ del self .l1_cache [evicted_node .key ]
144144 logger .debug ("Evicted key %s from L1 lock (freq: %d)" , evicted_node .key , evicted_node .freq )
145145
146146 def _background_sync (self ):
@@ -171,18 +171,18 @@ def _background_sync(self):
171171
172172 def invalidate (self , key : str ):
173173 with self .l1_lock :
174- if key in self .l1_lock :
175- node = self .l1_lock [key ]
174+ if key in self .l1_cache :
175+ node = self .l1_cache [key ]
176176 self .freq_map [node .freq ].remove_node (node )
177- del self .l1_lock [key ]
177+ del self .l1_cache [key ]
178178
179179 with self .l2_lock :
180180 if key in self .l2_store :
181181 del self .l2_store [key ]
182182
183183 def get_stats (self ) -> Dict [str , Any ]:
184184 with self .l1_lock :
185- l1_size = len (self .l1_lock )
185+ l1_size = len (self .l1_cache )
186186 with self .l2_lock :
187187 l2_size = len (self .l2_store )
188188
0 commit comments