equal
deleted
inserted
replaced
1309 n.markempty() |
1309 n.markempty() |
1310 n = n.next |
1310 n = n.next |
1311 |
1311 |
1312 self._cache.clear() |
1312 self._cache.clear() |
1313 |
1313 |
1314 def copy(self): |
1314 def copy(self, capacity=None): |
1315 result = lrucachedict(self.capacity) |
1315 """Create a new cache as a copy of the current one. |
|
1316 |
|
1317 By default, the new cache has the same capacity as the existing one. |
|
1318 But, the cache capacity can be changed as part of performing the |
|
1319 copy. |
|
1320 |
|
1321 Items in the copy have an insertion/access order matching this |
|
1322 instance. |
|
1323 """ |
|
1324 |
|
1325 capacity = capacity or self.capacity |
|
1326 result = lrucachedict(capacity) |
1316 |
1327 |
1317 # We copy entries by iterating in oldest-to-newest order so the copy |
1328 # We copy entries by iterating in oldest-to-newest order so the copy |
1318 # has the correct ordering. |
1329 # has the correct ordering. |
1319 |
1330 |
1320 # Find the first non-empty entry. |
1331 # Find the first non-empty entry. |
1321 n = self._head.prev |
1332 n = self._head.prev |
1322 while n.key is _notset and n is not self._head: |
1333 while n.key is _notset and n is not self._head: |
1323 n = n.prev |
1334 n = n.prev |
1324 |
1335 |
|
1336 # We could potentially skip the first N items when decreasing capacity. |
|
1337 # But let's keep it simple unless it is a performance problem. |
1325 for i in range(len(self._cache)): |
1338 for i in range(len(self._cache)): |
1326 result[n.key] = n.value |
1339 result[n.key] = n.value |
1327 n = n.prev |
1340 n = n.prev |
1328 |
1341 |
1329 return result |
1342 return result |