Skip to content

Conversation

ptiurin
Copy link
Contributor

@ptiurin ptiurin commented May 31, 2024

FIR-33386

I had to create our own cache class since the standard lru_cache has issues, namely:

  • Does not work well with async
  • Does not work well with Trino specifically

@ptiurin ptiurin marked this pull request as ready for review June 4, 2024 16:09
@ptiurin ptiurin requested a review from a team as a code owner June 4, 2024 16:09
Copy link
Collaborator

@stepansergeevitch stepansergeevitch left a comment

Choose a reason for hiding this comment

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

Also a question, is there any way to disable it?

from firebolt.utils.util import parse_url_and_params
from firebolt.utils.util import UtilCache, parse_url_and_params

_firebolt_async_system_engine_cache = UtilCache[Tuple[str, Dict[str, str]]]()
Copy link
Collaborator

Choose a reason for hiding this comment

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

why don't we have a global cache?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's global, since it's initialised on import. Or do you mean like a centralised one in, for example, connection.py? What would be an advantage of that?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was just thinking there is no need for separate cache instances for async and sync since it's always sync. Maybe we can have in somewhere in common?
Also, in I believe in extremely rare cases users can have both sync and async runtimes simultaneously and can reuse the cache in both, but not sure if that will ever happen. The main point is just to simplify

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added common.cache

@ptiurin
Copy link
Contributor Author

ptiurin commented Jun 5, 2024

Also a question, is there any way to disable it?

Not at the moment. Good point, we should be able to disable cache.

account_name: str,
api_endpoint: str,
) -> Tuple[str, Dict[str, str]]:
cache_key = f"{account_name}-{api_endpoint}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

We still create a key manually here. But I was thinking even more, just for get to have a signature def get(*key): and then inside do cache_key = self.create_key(*key) or something simillar

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, missed this one. I see where you're getting at now. My only problem with this is def set(*key, value) can lead to non-obvious errors when value is forgotten from the call, e.g. cache.set(account_name, api_endpoint) will work just fine, but lead to runtime issues. I've pushed a different approach with key accepting anything and using repr to convert to a hashable key. Hopefully it solves both issues.

@ptiurin ptiurin requested a review from stepansergeevitch June 5, 2024 21:11
Copy link

sonarqubecloud bot commented Jun 6, 2024

@ptiurin
Copy link
Contributor Author

ptiurin commented Jun 6, 2024

Integration tests are failing on an unrelated issue with the server response to an account with no user. It should be addressed in a separate PR.

@ptiurin ptiurin merged commit e1842ac into main Jun 6, 2024
@ptiurin ptiurin deleted the feat-cache-calls branch June 6, 2024 12:32
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.

2 participants