cuddly-jelly-27016
02/12/2025, 4:50 AM@task.
What changes were proposed in this pull request?
We create a new object called Cache which is groups all of the caching functionality, including the ability to set the version, cache serialization, the ability to ignore certain inputs in the cache key calculation (via setting cache_ignore_input_vars), and the set of cache policies applied. Here's the full definition of `Cache`:
class Cache:
version: Optional[str] = None
serialize: bool = False
ignored_inputs: Union[Tuple[str, ...], str] = ()
salt: str = ""
policies: Optional[Union[List[CachePolicy], CachePolicy]] = None
The first three fields are well known and map directly to existing cache-related concepts, now grouped in a single object. As for policies and salt, those are new concepts, the idea is to provide more complicated caching behavior based on the function definition. A CachePolicy is a protocol that specifies how versions are calculated. It exposes a single method called get_version that's called to produce a value, that we call version.
The Cache object applies the policies in the order in which they are defined to generate the final cache version. The process of generating the final value involves concatenating each version produced by a policy and then using SHA-256 to produce the final hexdigest (i.e. 64 hex characters) value.
Also worth mentioning that we require the definition of policies in case a Cache object is used.
All cache-related parameters are now officially deprecated (although they will keep being supported, potentially for a really long time). In order to make the migration seamless, the cache parameter in the @task decorator is now Union[bool, Cache] and mapping the old names to the new fields in Cache should be fairly simple.
As a final design decision, we also added a hook to help define a list of default policies. This might suit the more advanced users in case they need to maintain a central list of cache policies somewhere.
How was this patch tested?
Unit tests and local sandbox.
Setup process
Screenshots
Check all the applicable boxes
• I updated the documentation accordingly.
• All new and existing tests passed.
• All commits are signed-off.
Related PRs
Docs link
Summary by Bito
This PR implements a comprehensive refactoring of Flyte tasks' caching functionality, transitioning from explicit cache parameters to a kwargs-based approach with a new Cache class. The changes include enhanced pod template support, improved cache policy validation, and authentication system refinements. The implementation features updated error messaging for cache policy requirements and modified task decorator for pod template parameter handling, while maintaining backward compatibility through policy-based version generation.
Unit tests added: True
Estimated effort to review (1-5, lower is better): 5
flyteorg/flytekitcuddly-jelly-27016
02/13/2025, 8:49 PM