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

Move the cache implementation behind an interface #614

Merged
merged 1 commit into from
Jun 1, 2022

Conversation

josephschorr
Copy link
Member

To allow for different implementations based on platform

@josephschorr josephschorr requested review from jakedt and a team May 24, 2022 16:26
@github-actions github-actions bot added area/CLI Affects the command line area/datastore Affects the storage system area/dispatch Affects dispatching of requests labels May 24, 2022
@@ -24,7 +25,7 @@ const (
)

// Complete converts the cache config into a ristretto cache config.
Copy link
Member

Choose a reason for hiding this comment

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

Fix the comment.

"github.com/dgraph-io/ristretto"
)

// NewCache creates a new ristretto cache from the given config.
Copy link
Member

Choose a reason for hiding this comment

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

Should we stick to the "return structs accept interfaces" mantra here?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can, but it does mean that NewCache's signature will change based on the platform, which may cause issues in certain compilation targets

Copy link
Member

Choose a reason for hiding this comment

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

I don't get it. In this case it's always going to be a ristretto cache coming out of cache_ristretto. The method should probably be called NewRistrettoCache, and it will be totally missing on the wasm arch. If there were a wasm compatible version it would be called NewHashmapCache or something, and its version of wrapped would be specific to that cache impl.

Copy link
Member Author

Choose a reason for hiding this comment

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

If there were a wasm compatible version it would be called NewHashmapCache or something

Actually, no. The whole point is that it is NewCache regardless of platform, so that when it is invoked outside of the package, the caller does not need to know on which platform the code is operating. Otherwise, it would fail to compile.

pkg/cache/cache_ristretto.go Show resolved Hide resolved
@josephschorr
Copy link
Member Author

Updated

"github.com/dgraph-io/ristretto"
)

// NewCache creates a new ristretto cache from the given config.
Copy link
Member

Choose a reason for hiding this comment

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

I don't get it. In this case it's always going to be a ristretto cache coming out of cache_ristretto. The method should probably be called NewRistrettoCache, and it will be totally missing on the wasm arch. If there were a wasm compatible version it would be called NewHashmapCache or something, and its version of wrapped would be specific to that cache impl.

@jakedt jakedt force-pushed the cache-interface branch from f45b802 to c49ea32 Compare June 1, 2022 13:07
@jakedt jakedt enabled auto-merge June 1, 2022 13:08
@jakedt jakedt merged commit bbb3683 into authzed:main Jun 1, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jun 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/CLI Affects the command line area/datastore Affects the storage system area/dispatch Affects dispatching of requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants