guava cache for table like structure

890 views
Skip to first unread message

Andrei Sereda

unread,
May 30, 2012, 7:34:02 PM5/30/12
to guava-...@googlegroups.com
Hi Everybody,

I wanted to ask your advice on how to best implement in-memory "table" like structure using K/V store (guava cache). The table has a PK which resolves to a unique element. However there are also secondary indexes which map a value to a collection of elements (Multimap in google's parlance). Add cache semantics to the above data structure (eviction, concurrency, data population/cache loader, refresh etc.) and that's pretty much what is needed.

To give a concrete example imagine a User object having attributes [id, country]. Sometimes you search by (unique) attribute id, sometimes you want all users from country XYZ.

Probably it is not directly related to guava however I was wondering if combination of cache and multimaps (or Table?) can achieve desired result ? What's the best way to keep indexes in sync ?

Thanks for your help,
Andrei.

Louis Wasserman

unread,
May 31, 2012, 10:46:07 AM5/31/12
to Andrei Sereda, guava-...@googlegroups.com
If concurrency is in play, then I don't think you'll be able to use Guava like this.  It's typically difficult or impossible to shove two concurrency abstractions together and expect their synchronization guarantees to work together like that.

I suspect that a proper in-memory database would probably be of more use to you?

Kevin Bourrillion

unread,
May 31, 2012, 1:06:59 PM5/31/12
to Louis Wasserman, Andrei Sereda, guava-...@googlegroups.com
Friendly reminder from the guava-libraries.googlecode.com main page:

To get help on a specific question or problem, post a question to Stack Overflow with the tag "guava". We monitor these questions using this RSS feed.)

--
Kevin Bourrillion @ Google
Java Core Libraries Team
http://guava-libraries.googlecode.com

Paul Bellora

unread,
May 31, 2012, 1:15:51 PM5/31/12
to Kevin Bourrillion, Louis Wasserman, Andrei Sereda, guava-...@googlegroups.com

Andrei Sereda

unread,
May 31, 2012, 1:25:20 PM5/31/12
to guava-...@googlegroups.com, Kevin Bourrillion, Louis Wasserman, Andrei Sereda
Hi,

Apologies if I misused the channel. This group seemed more active than stackoverlow. I'll be glad to discuss this question there.

Kevin Bourrillion

unread,
May 31, 2012, 1:44:24 PM5/31/12
to Andrei Sereda, guava-...@googlegroups.com, Louis Wasserman
Ah. If you're having trouble getting an answer on SO, feel free to ping the list here but just send us a link to the SO page so we can keep the answers in one place!

Andrei Sereda

unread,
May 31, 2012, 2:53:07 PM5/31/12
to guava-...@googlegroups.com, Andrei Sereda, Louis Wasserman
Thanks, Kevin. I'll wait for an answer on SO.

Andrei Sereda

unread,
Jun 6, 2012, 8:18:30 PM6/6/12
to guava-...@googlegroups.com, Andrei Sereda, Louis Wasserman
Ping.
Eager to hear your opinions.
Reply all
Reply to author
Forward
0 new messages