Skip to content

Conversation

@thewhaleking
Copy link
Collaborator

@thewhaleking thewhaleking commented Mar 4, 2025

Caches commonly used functions on-disk

@thewhaleking thewhaleking linked an issue Mar 5, 2025 that may be closed by this pull request
@thewhaleking thewhaleking marked this pull request as ready for review March 6, 2025 15:59
@thewhaleking thewhaleking changed the title [WIP] On-disk cache On-disk cache Mar 6, 2025


def _create_table(c, conn, table_name):
c.execute(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can simply use Connection ctx manager:

with conn:
  conn.execute

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this isn't available on 3.9, but can double-check.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it is available, but do we want to do that rather than just reuse the same cursor object repeatedly?


def _insert_into_cache(c, conn, table_name, key, result, chain):
try:
c.execute(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

connection context manager?

chain = self.url
if not (local_chain := _check_if_local(chain)) or not USE_CACHE:
result = _retrieve_from_cache(c, table_name, key, chain)
if result is not None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to cache None value?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to cache None value?

Yes. But none of the cached methods can ever return None.

@thewhaleking thewhaleking merged commit dcafc03 into staging Mar 11, 2025
@thewhaleking thewhaleking deleted the feat/thewhaleking/on-disk-cache branch March 11, 2025 19:42
@ibraheem-abe ibraheem-abe mentioned this pull request Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TODO: Preload the caches

4 participants