Skip to content

Composite Keys with Caffein #603

Answered by ben-manes
elrapha asked this question in Q&A
Discussion options

You must be logged in to vote

A "composite key" refers to a key that is composed of multiple properties. For example a Point(int x, int y) would be composed into an object and used as a map key. In that case an object that has a valid equals and hashCode implementation, e.g. Java records, would be perfect as a cache key.

If you instead are asking how to have multiple keys map to a single value and keep it consistent, then that is a harder problem. These are like database indexes to a row. Similar to a database you can use a primary key (key->value) and secondary keys (key->primary), and then a locking scheme to ensure consistency. A long time ago I wrote an article showing how this can be done using lock striping to d…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ben-manes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants