Skip to content
This repository was archived by the owner on Nov 20, 2025. It is now read-only.

Commit f760731

Browse files
authored
Move lru_cache definitions to __init__ (#30)
Using the lru_cache decorators on class methods, the ones that have a reference to `self`, will also cache self. So we move it to the __init__ of the class (DIS-2913)
1 parent 54d8c84 commit f760731

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

dissect/esedb/esedb.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ def __init__(self, fh: BinaryIO, impacket_compat: bool = False):
4545

4646
self.catalog = Catalog(self, pgnoFDPMSO)
4747

48+
self.page = lru_cache(4096)(self.page)
49+
4850
@cached_property
4951
def has_small_pages(self) -> bool:
5052
"""Return whether this database has small pages (<= 8K)."""
@@ -82,7 +84,6 @@ def read_page(self, num: int) -> bytes:
8284

8385
return buf
8486

85-
@lru_cache(maxsize=4096)
8687
def page(self, num: int) -> Page:
8788
"""Get a logical page.
8889

dissect/esedb/record.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ def __init__(self, table: Table, node: Node):
151151
self._tagged_data_view = xmemoryview(tagged_field_data, "<I")
152152
self._tagged_fields[first_tagged_field.identifier] = first_tagged_field
153153

154+
self._get_tag_field = lru_cache(4096)(self._get_tag_field)
155+
self._find_tag_field_idx = lru_cache(4096)(self._find_tag_field_idx)
156+
154157
def get(self, column: Column, raw: bool = False) -> RecordValue:
155158
"""Retrieve the value for the specified column.
156159
@@ -355,12 +358,10 @@ def _get_tagged(self, column: Column) -> Optional[bytes]:
355358

356359
return tag_field, value
357360

358-
@lru_cache(4096)
359361
def _get_tag_field(self, idx: int) -> TagField:
360362
"""Retrieve the :class:`TagField` at the given index in the ``TAGFLD`` array."""
361363
return TagField(self, self._tagged_data_view[idx])
362364

363-
@lru_cache(4096)
364365
def _find_tag_field_idx(self, identifier: int, is_derived: bool = False) -> Optional[TagField]:
365366
"""Find a tag field by identifier and optional derived flag.
366367

0 commit comments

Comments
 (0)