rattler icon indicating copy to clipboard operation
rattler copied to clipboard

refactor: put PackageCache into an enum in preparation for a multi-layered package cache

Open kelvinou01 opened this issue 1 year ago • 6 comments

Description

As per https://github.com/conda/rattler/issues/43, we want to implement layered package caches for Rattler. Putting PacakgeCache into an enum allows switching between implementations (SingletonPackageCache and LayeredPackageCache)

I'm considering both traits and enums. Leaning towards enum because:

  • My impression is that we don't allow downstream users to add their own PackageCache types, thus a closed set of types (enum) is more suitable.
  • Enums are more performant

Stuff to note

  • This will be a breaking change
  • To let PackageCache be public, I had to make PackageCacheInner public as well (even though inner is a private struct field), not sure if there's a way not to.

kelvinou01 avatar Sep 03 '24 07:09 kelvinou01

Hey! Thanks for making this PR! Im wondering what your design considerations are. Why have two separate implementations? Isnt a non-layered cache just cache with one layer?

baszalmstra avatar Sep 03 '24 07:09 baszalmstra

Isnt a non-layered cache just cache with one layer?

Hey @baszalmstra! I was actually referencing this

We could introduce a trait for PackageCache that is implemented for both the current implementation as well as a layered version.

Maybe we can allow users to pick between the singleton and layered implementations, while we polish the latter? Or should we just create a layered implementation and have it be shipped to users (with the default being a cache with one layer)

kelvinou01 avatar Sep 03 '24 07:09 kelvinou01

Maybe we can allow users to pick between the singleton and layered implementations, while we polish the latter? Or should we just create a layered implementation and have it be shipped to users (with the default being a cache with one layer)

Yeah, I think (in hindsight) that makes the most sense.

FYI I'm also about to merge a relatively large refactor of the PackageCache in https://github.com/conda/rattler/pull/837.

baszalmstra avatar Sep 03 '24 07:09 baszalmstra

Thanks for the heads up on the PR!

Also just to be sure, which idea did you think made the most sense, using the enum or not using it?

kelvinou01 avatar Sep 03 '24 08:09 kelvinou01

Also just to be sure, which idea did you think made the most sense, using the enum or not using it?

I think a single implementation makes more sense. But if you feel uncertain about the implementation using an enum is fine for me as well.

baszalmstra avatar Sep 03 '24 08:09 baszalmstra

#837 was just merged, you might have a few conflicts.

baszalmstra avatar Sep 03 '24 09:09 baszalmstra