Documentation

Manage the Last Value Cache

The InfluxDB 3 Core Last Value Cache (LVC) lets you cache the most recent values for specific fields in a table, improving the performance of queries that return the most recent value of a field for specific series or the last N values of a field.

The LVC is an in-memory cache that stores the last N number of values for specific fields of series in a table. When you create an LVC, you can specify what fields to cache, what tags to use to identify each series, and the number of values to cache for each unique series. An LVC is associated with a table, which can have multiple LVCs.

Consider a dataset with the following schema (similar to the home sensor sample dataset):

  • home (table)
    • tags:
      • room
        • kitchen
        • living room
      • wall
        • north
        • east
        • south
    • fields:
      • co (integer)
      • temp (float)
      • hum (float)

If you cache the last value for each field per room and wall, the LVC looks similar to this:

roomwallcohumtemptime
Kitcheneast2636.522.72025-04-22T20:00:00Z
Living Roomnorth1736.422.22025-04-22T20:00:00Z
Living Roomsouth1636.322.12025-04-22T20:00:00Z

If you cache the last four values of each field per room and wall, the LVC looks similar to the following:

roomwallcohumtemptime
Kitcheneast2636.522.72025-04-22T20:00:00Z
Kitcheneast936.022.72025-04-22T17:00:00Z
Kitcheneast336.222.72025-04-22T15:00:00Z
Kitcheneast036.122.72025-04-22T10:00:00Z
Living Roomnorth1736.422.22025-04-22T20:00:00Z
Living Roomnorth535.922.62025-04-22T17:00:00Z
Living Roomnorth136.122.32025-04-22T15:00:00Z
Living Roomnorth036.021.82025-04-22T10:00:00Z
Living Roomsouth1636.322.12025-04-22T20:00:00Z
Living Roomsouth435.822.52025-04-22T17:00:00Z
Living Roomsouth036.022.32025-04-22T15:00:00Z
Living Roomsouth035.921.82025-04-22T10:00:00Z

Null column values

Null column values are still considered values and are cached in the LVC. If you write data to a table and don’t provide a value for an existing column, the column value is cached as null.

Important things to know about the Last Value Cache

LVCs are stored in memory; the larger the cache, the more memory your InfluxDB 3 node requires to maintain it. Consider the following:

High cardinality key columns

“Cardinality” refers to the number of unique key column combinations in your cached data. While the InfluxDB 3 storage engine is not limited by cardinality, it does affect the LVC. Higher cardinality increases memory requirements for storing the LVC and can affect LVC query performance. We recommend the following:

  • Only use tags important to your query workload as key columns in the LVC. Caching unnecessary tags or fields as key columns results in higher cardinality without any benefit.
  • Avoid including high-cardinality key columns in your LVC.
  • Don’t include multiple high-cardinality key columns in your LVC.

To estimate total key column cardinality in an LVC, use the following equation:

num_uniq_col_val_N [× num_uniq_col_val_N …] = key_column_cardinality
  • Copy
  • Fill window

Value count

By increasing the number of values to store in the LVC, you increase the number of rows stored in the cache and the amount of memory required to store them. Be judicious with the number of values to store. This count is per unique key column combination. If you include two tags as key columns, one with three unique values and the other with 10, you could have up to 30 unique key column combinations. If you want to keep the last 10 values, you could potentially have 300+ rows in the cache.

To get an idea of the number of rows required to cache the specified number of values, use the following equation:

key_column_cardinality × count = number_of_rows
  • Copy
  • Fill window

Last Value Caches are flushed when the server stops

Because the LVC is an in-memory cache, the cache is flushed any time the server stops. After a server restart, InfluxDB 3 Core only writes new values to the LVC when you write data, so there may be a period of time when some values are unavailable in the LVC.

Defining value columns

When creating an LVC, if you include the --value-columns options to specify which fields to cache as value columns, any new fields added in the future will not be added to the cache.

However, if you omit the --value-columns option, all columns other than those specified as --key-columns are cached as value columns, including columns that are added later.


Was this page helpful?

Thank you for your feedback!


The future of Flux

Flux is going into maintenance mode. You can continue using it as you currently are without any changes to your code.

Read more

Now Generally Available

InfluxDB 3 Core and Enterprise

Start fast. Scale faster.

Get the Updates

InfluxDB 3 Core is an open source, high-speed, recent-data engine that collects and processes data in real-time and persists it to local disk or object storage. InfluxDB 3 Enterprise builds on Core’s foundation, adding high availability, read replicas, enhanced security, and data compaction for faster queries and optimized storage. A free tier of InfluxDB 3 Enterprise is available for non-commercial at-home or hobbyist use.

For more information, check out: