Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added default CacheAdapter lifecycle hook #766

Merged
merged 3 commits into from
Mar 19, 2024
Merged

Conversation

zilto
Copy link
Collaborator

@zilto zilto commented Mar 18, 2024

This follows a similar logic to hamilton.plugins.h_diskcache, but uses the standard shelve library. It has the same API as the diskcache, but provides less utilities to manage cache size.

Changes

  • added a CacheAdapter to hamilton.lifecycle.default
  • added relevant tests, derived from tests/plugins/h_diskcache

How I tested this

  • ran tests successfully locally

Notes

  • one edge case regarding cache history is mentioned in TODOs, but it shouldn't affect usability.

Checklist

  • PR has an informative and human-readable title (this will be pulled into the release notes)
  • Changes are limited to a single goal (no scope creep)
  • Code passed the pre-commit check & code is left cleaner/nicer than when first encountered.
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future TODOs are captured in comments
  • Project documentation has been updated if adding/changing functionality.

@zilto zilto requested a review from skrawcz March 18, 2024 17:31
@zilto zilto marked this pull request as draft March 18, 2024 17:36
@zilto zilto marked this pull request as ready for review March 18, 2024 17:36
@skrawcz
Copy link
Collaborator

skrawcz commented Mar 18, 2024

@zilto this should have a companion example, and also docs entry.

Copy link
Collaborator

@elijahbenizzy elijahbenizzy left a comment

Choose a reason for hiding this comment

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

Looks good! A few comments to fix after, merging.

hamilton/lifecycle/default.py Outdated Show resolved Hide resolved
- the callable hash is stored in `used_nodes_hash` because it's required to create the
key in `run_after_node_execution` and the callable won't be accessible to recompute it
"""
if node_name not in self.cache_vars:
Copy link
Collaborator

Choose a reason for hiding this comment

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

For afterwards -- we may want to make this a set? Odds are high this is not a slow operation, but it could get O(n**2) which we don't want.

@elijahbenizzy elijahbenizzy merged commit 434554a into main Mar 19, 2024
14 of 23 checks passed
@elijahbenizzy elijahbenizzy deleted the feat/stdlib-cache-hook branch March 19, 2024 04:17
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.

3 participants