Nuxeo / DAM / PAM / ECM specialistsContact
Home/Insights/Nuxeo
Insights

Let’s Talk About KVS (Key Value Stores)

Jul 10, 20262 min read

Let’s Talk About KVS (Key Value Stores)

This week we're getting technical again, diving into a lesser-known feature of Nuxeo: Key Value Stores, or KVS.

I mentioned KVS briefly in a previous edition about making Nuxeo more secure, and I got a surprising number of DMs saying things like "Wait... this exists?"

So let's unpack it.

First of all, KVS isn't something you'll see in the Nuxeo UI, and you won't find it in Nuxeo Studio either 😅. But it's there-and super useful.

💡 What's a Key Value Store?

In short, it's a service for storing any kind of data in Nuxeo using simple key/value pairs. It's mainly intended for caching or temporary storage, but depending on the implementation, you can use it to store data indefinitely too (just not with the in-memory store).

🔧 Available Implementations

Nuxeo provides four out-of-the-box implementations:

  • MemKeyValueStore (in-memory)
  • RedisKeyValueStore - deprecated, but still functional
  • SQLKeyValueStore
  • MongoDBKeyValueStore

In MongoDB, this just becomes a regular collection in your database. You can store anything-from a simple string to a byte array-optionally with a TTL (Time To Live).

🛠️ Real-World Use Cases

I looked at ~30 recent Nuxeo projects I worked on, and KVS popped up in many ways:

  • Temporarily storing values while publishing to external systems
  • Holding intermediate data during import
  • Tracking failed login attempts
  • Counting blocked users
  • Saving custom config settings
  • Storing tokens/codes used in auth flows
  • Tracking export stats (e.g., # of docs zipped)
  • Holding user or system notifications
  • etc..

Basically, whenever you need to persist data that doesn't belong in a document or vocabulary-this is your tool.

🚀 How to Use KVS in Nuxeo

Super straightforward.

Step 1 - Declare your store in your XML contribution:

<extension target="org.nuxeo.runtime.kv.KeyValueService" point="configuration">
  <store name="transcodingFailureNotification" class="org.nuxeo.ecm.core.mongodb.kv.MongoDBKeyValueStore">
    <property name="collection">transcodingFailureNotification</property>
  </store>
</extension>

Step 2 - Store a value (with or without a TTL):

KeyValueStore kvStore = Framework.getService(KeyValueService.class)
    .getKeyValueStore("transcodingFailureNotification");
kvStore.put(doc.getId(), failureMessage); // no TTL = stored indefinitely

Step 3 - Retrieve the value later:

KeyValueStore kvStore = Framework.getService(KeyValueService.class)
    .getKeyValueStore("transcodingFailureNotification");
String failureMessage = kvStore.getString(doc.getId());

I hope this helps you discover another hidden gem in Nuxeo. KVS is simple, flexible, and incredibly handy once you know it exists.

🔧 Let me know if you're using KVS in other ways-I'd love to hear.

← All insights

Keep reading

Related insights

Talk to a Maretha Consultant

Tell us what you're struggling with, and we'll tell you how we can help you.

Talk to us