Skip to content

Commit

Permalink
Add refresh_caches method
Browse files Browse the repository at this point in the history
  • Loading branch information
MehmedGIT authored Dec 1, 2022
1 parent c992296 commit a07f7e8
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions ocrd_models/ocrd_models/ocrd_mets.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,29 +71,7 @@ def __init__(self, **kwargs):

# If cache is enabled
if self._cache_flag:

# Cache for the files (mets:file) - two nested dictionaries
# The outer dictionary's Key: 'fileGrp.USE'
# The outer dictionary's Value: Inner dictionary
# The inner dictionary's Key: 'file.ID'
# The inner dictionary's Value: a 'file' object at some memory location
self._file_cache = {}

# Cache for the pages (mets:div)
# The dictionary's Key: 'div.ID'
# The dictionary's Value: a 'div' object at some memory location
self._page_cache = {}

# Cache for the file pointers (mets:fptr) - two nested dictionaries
# The outer dictionary's Key: 'div.ID'
# The outer dictionary's Value: Inner dictionary
# The inner dictionary's Key: 'fptr.FILEID'
# The inner dictionary's Value: a 'fptr' object at some memory location
self._fptr_cache = {}

# Note, if the empty_mets() function is used to instantiate OcrdMets
# Then the cache is empty even after this operation
self._fill_caches()
self.refresh_caches()

def __exit__(self):
"""
Expand Down Expand Up @@ -165,7 +143,32 @@ def _clear_caches(self):
self._file_cache = None
self._page_cache = None
self._fptr_cache = None

def refresh_caches(self):
if self._cache_flag:
# Cache for the files (mets:file) - two nested dictionaries
# The outer dictionary's Key: 'fileGrp.USE'
# The outer dictionary's Value: Inner dictionary
# The inner dictionary's Key: 'file.ID'
# The inner dictionary's Value: a 'file' object at some memory location
self._file_cache = {}

# Cache for the pages (mets:div)
# The dictionary's Key: 'div.ID'
# The dictionary's Value: a 'div' object at some memory location
self._page_cache = {}

# Cache for the file pointers (mets:fptr) - two nested dictionaries
# The outer dictionary's Key: 'div.ID'
# The outer dictionary's Value: Inner dictionary
# The inner dictionary's Key: 'fptr.FILEID'
# The inner dictionary's Value: a 'fptr' object at some memory location
self._fptr_cache = {}

# Note, if the empty_mets() function is used to instantiate OcrdMets
# Then the cache is empty even after this operation
self._fill_caches()

@property
def unique_identifier(self):
"""
Expand Down

0 comments on commit a07f7e8

Please sign in to comment.