Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
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