Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move lru_cache definitions to __init__ #30

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dissect/esedb/esedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def __init__(self, fh: BinaryIO, impacket_compat: bool = False):

self.catalog = Catalog(self, pgnoFDPMSO)

self.page = lru_cache(4096)(self.page)

@cached_property
def has_small_pages(self) -> bool:
"""Return whether this database has small pages (<= 8K)."""
Expand Down Expand Up @@ -82,7 +84,6 @@ def read_page(self, num: int) -> bytes:

return buf

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

Expand Down
5 changes: 3 additions & 2 deletions dissect/esedb/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ def __init__(self, table: Table, node: Node):
self._tagged_data_view = xmemoryview(tagged_field_data, "<I")
self._tagged_fields[first_tagged_field.identifier] = first_tagged_field

self._get_tag_field = lru_cache(4096)(self._get_tag_field)
self._find_tag_field_idx = lru_cache(4096)(self._find_tag_field_idx)

def get(self, column: Column, raw: bool = False) -> RecordValue:
"""Retrieve the value for the specified column.

Expand Down Expand Up @@ -355,12 +358,10 @@ def _get_tagged(self, column: Column) -> Optional[bytes]:

return tag_field, value

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

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

Expand Down
Loading