World is now on Opti ID! Learn more

Jonas Bergqvist
Feb 28, 2025
  959
(6 votes)

Optimizely Graph Cache: The Power of "Item"

In the world of content delivery, speed is king. A high cache hit ratio is the secret weapon for delivering snappy performance and happy users. But how do you achieve that? One powerful trick lies in understanding the difference between "items" and "item" in your GraphQL queries.

The Cache Challenge: Lists vs. Specifics

GraphQL's flexibility often leads to queries fetching lists ("items"). While necessary for many scenarios, this can hinder caching. Why? Because even a list with one item requires the cache to consider potential changes to any content, leading to frequent cache invalidations.

The "Item" Advantage: Precision Caching

Enter the "item" query. When you request a single item by its unique identifier, you unlock granular, efficient caching.

How to Leverage "Item" for Optimal Caching:

  • Improve Cache Hit Ratio: Swap "items" for "item" when fetching a single entity. It's a small change with big results.
  • Unique Identifier-Driven Queries: Only use "item" when targeting a specific item via its unique identifier (relative paths, URLs, codes, etc.).

Cache hit example for query with "item"

Cache hit example for query with "items"

Practical Example

Instead of

query GetItem($relativePath: String) {
  Content(limit:1 where: { RelativePath: { eq: $relativePath } }) {
    items { Name }
  }
}

Use

query GetItem($relativePath: String) {
  Content(where: { RelativePath: { eq: $relativePath } }) {
    item { Name }
  }
}

Conclusion

Using "item" for single entity retrieval based on unique identifiers dramatically improves cache hit ratios, enhancing performance and user experience. It's a simple, powerful technique to unlock the full potential of your GraphQL cache.

Feb 28, 2025

Comments

Surjit Bharath
Surjit Bharath Mar 17, 2025 02:19 PM

5 star tip. Thanks Jonas

Please login to comment.
Latest blogs
Password protect your Optimizely CMS content

Want to share some private content on your website with basic password protection? You can do this with an Optimizely form and Audience based...

Brian Gerby | Jul 17, 2025 |

Importing Form Submission Data into Optimizely Forms Using DdsPermanentStorage

Recently, we needed to import a large number of records from a third-party system into Optimizely Forms . The data was available in CSV format, and...

Pawan Singh | Jul 16, 2025

Cancelling CMS Scheduled Jobs

From flags to tokens: making Optimizely CMS scheduled jobs more elegant with .NET cancellation tokens.

Damian Smutek | Jul 16, 2025 |

Optimizely Frontend Hosting: Deploy Without PowerShell Using the @kunalshetye/opticloud Package

In my last two blog posts, I walked through how to get started with deploying a headless app to Optimizely Frontend Hosting using PowerShell and th...

Szymon Uryga | Jul 15, 2025