Skip to content

Commit

Permalink
Set size of library cache (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nfsaavedra authored Jan 23, 2024
1 parent c5bed3e commit 7ebfad1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
16 changes: 16 additions & 0 deletions coqpyt/coq/proof_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ def __load_library(
coq_file.close()
return context

@staticmethod
def set_cache_size(size: Optional[int]):
_AuxFile._AuxFile__load_library = lru_cache(maxsize=size)(
_AuxFile.__load_library.__wrapped__,
)

@staticmethod
def get_library(
library_name: str,
Expand Down Expand Up @@ -732,6 +738,16 @@ def __is_proven(self, proof: ProofTerm) -> bool:
and "Admitted" not in proof.steps[-1].step.short_text
)

@staticmethod
def set_library_cache_size(size: Optional[int]):
"""Sets the size of the cache used to store the libraries of the Coq files.
Args:
size (Optional[int]): The size of the cache. If None, the cache
will have no limit.
"""
_AuxFile.set_cache_size(size)

@property
def proofs(self) -> List[ProofTerm]:
"""Gets all the closed proofs in the file and their corresponding steps.
Expand Down
10 changes: 10 additions & 0 deletions coqpyt/tests/test_cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from coqpyt.coq.proof_file import _AuxFile, ProofFile


def test_set_cache_size():
_AuxFile.set_cache_size(256)
_AuxFile._AuxFile__load_library.cache_info().maxsize == 256
_AuxFile.set_cache_size(512)
_AuxFile._AuxFile__load_library.cache_info().maxsize == 512
ProofFile.set_library_cache_size(256)
_AuxFile._AuxFile__load_library.cache_info().maxsize == 256

0 comments on commit 7ebfad1

Please sign in to comment.