Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 6 Current »

Problem

  • Repeated access to info held in a data store.

  • Cached data to be consistent with data in the data store.

Solution

  • Caching systems provide read-through and write-through/write-behind operations.

image-20240812-154438.png
  1. Determine whether the item is currently held in the cache.

  2. If the item is not currently in the cache, read the item from the data store.

  3. Store a copy of the item in the cache.

Caching in practice

private static ConnectionMultiplexer Connection;

// Redis connection string information
private static Lazy<ConnectionMultiplexer> lazyConnection = new Lazy<ConnectionMultiplexer>(() =>
{
    string cacheConnection = ConfigurationManager.AppSettings["CacheConnection"].ToString();
    return ConnectionMultiplexer.Connect(cacheConnection);
});

public static ConnectionMultiplexer Connection => lazyConnection.Value;
  • No labels