The CachedTopicRepository
decorates another ITopicRepository
implementation with an in-memory cache. It is recommended that web applications decorate their ITopicRepository
implementation.
When topics are requested, they are pulled from the cache, if they exist; otherwise, they are pulled from the underlying ITopicRepository
implementation, and then cached. Similarly, when topics are e.g. saved or moved, the updated versions are persisted to the underlying ITopicRepository
, and then updated in the cache.
Installation can be performed by providing a <PackageReference /
> to the OnTopic.Data.Caching
NuGet package.
<Project Sdk="Microsoft.NET.Sdk.Web">
…
<ItemGroup>
<PackageReference Include="OnTopic.Data.Caching" Version="5.0.0" />
</ItemGroup>
</Project>
var sqlTopicRepository = new SqlTopicRepository(connectionString);
var cachedTopicRepository = new CachedTopicRepository(sqlTopicRepository);
var rootTopic = cachedTopicRepository.Load();