![]() |
VOOZH | about |
dotnet add package Diginsight.SmartCache.Externalization.Http --version 3.7.1.13
NuGet\Install-Package Diginsight.SmartCache.Externalization.Http -Version 3.7.1.13
<PackageReference Include="Diginsight.SmartCache.Externalization.Http" Version="3.7.1.13" />
<PackageVersion Include="Diginsight.SmartCache.Externalization.Http" Version="3.7.1.13" />Directory.Packages.props
<PackageReference Include="Diginsight.SmartCache.Externalization.Http" />Project file
paket add Diginsight.SmartCache.Externalization.Http --version 3.7.1.13
#r "nuget: Diginsight.SmartCache.Externalization.Http, 3.7.1.13"
#:package Diginsight.SmartCache.Externalization.Http@3.7.1.13
#addin nuget:?package=Diginsight.SmartCache.Externalization.Http&version=3.7.1.13Install as a Cake Addin
#tool nuget:?package=Diginsight.SmartCache.Externalization.Http&version=3.7.1.13Install as a Cake Tool
diginsight SmartCache provides hybrid, distributed, multilevel caching based on age sensitive data management.<br>
SmartCache is hybrid as it caches data in-memory and on external RedIs databases.<br>
In-memory cache ensure 0-latency for most recently used data and ensures low pressure (and reduced cost) on the external RedIs database.<br>SmartCache is distributed as cache entries on different nodes of a multiinstance application are sinchronized automatically, to avoid flickering of values when querying the same data on different nodes.<br>SmartCache is based on age sensitive data management as cache entries are returned based on a requested MaxAge parameter.<br>
Data is returned from the cache if the cache entry corresponding to the request is compatible with the requested MaxAge.<br>
Otherwise data is obtained by the cache data source provided as a delegate.
<br>Any application, at any time, can access data with different age criteria, according to the specific use for which data is requested.<br>The image bleow illustrates shows an application requesting data with age 5 minutes to a multinode application:<br>
Data loaded by any request, is made available for the benefit of further requests (as long as compatible with their MaxAge requirement).<br> As an example, an immediately successive request for the same data with age 1 minute will be satisfied by the cache entry loaded by the first request.
SmartCache is Multilevel: The same entries can be cached in multiple levels (frontend, backend or further levels). <br>At any level, data is returned from the cache if the requested MaxAge is compatible with the cache entry. otherwise data is requested to the further levels.<br>
In case all levels entries contains old data, incompatible with the request MaxAge requirement, data is requested to the real data provider.
SmartCache is Optimized: as:
SmartCache supports caching data with low cost and high performance.<br> In particular, 0 latency is ensured on in-memory cache hits. also, pressure on external RedIS resource is low as most frequently used entries are managed in-memory.
Also, 0 latency can be obtained since the first and for every call by means of Cache Preloading and Cache Invalidation. <br>
the following image illustrates the five SmartCache tenets:
Using Smartcache the following events are involved when interacting with data:<br>
IInvalidatable are notified every time Invalidate action is triggered so that they can be evicted when needed.The following image illustrates the described SmartCache events:<br>
The following paragraph:<br>
STEPS TO USE SMARTCACHE <br>
discusses basic steps to start using Diginsight.SmartCache.<br>
The steps, code snippets and images below were created by means of the working SampleWebAPI available into smartcache.samples repository.<br>
Diginsight.SmartCacheIn the first step you can just add a Diginsight.SmartCache reference to your code:<br>
In case of multiinstance applications Diginsight.SmartCache.Externalization.ServiceBus may be needed to support instances synchronization.
In case of AspNetCore applications Diginsight.SmartCache.Externalization.AspNetCore may be useful to support dynamic MaxAge specification from http request headers.
SmartCache services and default settings must be registered into the startup sequence ConfigureServices methdod.<br> The code snippets below are available as working samples within the smartcache.samples repository.
public void ConfigureServices(IServiceCollection services)
{
...
// (optional) reads RedIs connection string
services.ConfigureRedisCacheSettings(configuration);
...
// configures Diginsight:SmartCache config section with default
services.ConfigureClassAware<SmartCacheCoreOptions>(configuration.GetSection("Diginsight:SmartCache"));
var smartCacheBuilder = services.AddSmartCache(configuration, environment, loggerFactory)
.AddHttp();
// (optional) ServiceBus connection
IConfigurationSection smartCacheServiceBusConfiguration = configuration.GetSection("Diginsight:SmartCache:ServiceBus");
if (!string.IsNullOrEmpty(smartCacheServiceBusConfiguration[nameof(SmartCacheServiceBusOptions.ConnectionString)]) && !string.IsNullOrEmpty(smartCacheServiceBusConfiguration[nameof(SmartCacheServiceBusOptions.TopicName)]))
{
smartCacheBuilder.SetServiceBusCompanion(
static (c, _) =>
{
IConfiguration sbc = c.GetSection("Diginsight:SmartCache:ServiceBus");
return !string.IsNullOrEmpty(sbc[nameof(SmartCacheServiceBusOptions.ConnectionString)])
&& !string.IsNullOrEmpty(sbc[nameof(SmartCacheServiceBusOptions.TopicName)]);
},
sbo =>
{
configuration.GetSection("Diginsight:SmartCache:ServiceBus").Bind(sbo);
sbo.SubscriptionName = SmartCacheServiceBusSubscriptionName;
});
}
services.TryAddSingleton<ICacheKeyProvider, MyCacheKeyProvider>();
}
The image below shows Diginsight.SmartCache settings with default MaxAge and Expiration values for cache entries.
"SmartCache": {
"MaxAge": "00:05:00",
//"MaxAge@...": "00:01:00",
//"MaxAge@...": "00:10:00",
"AbsoluteExpiration": "1.00:00",
"SlidingExpiration": "04:00:00",
"ServiceBus": {
"ConnectionString": "", // Key Vault
"TopicName": "smartcache-commonapi"
}
}
NB.
- ServiceBus configuration is required only in case of multiinstance applications where instances cache entries need to be synchronized.
- RedIs configuration is required only in case external backing storage is available to save evicted cache entries. this allows reducing cache miss rate and mininize access to data sources.
Diginsight.SmartCache will manage cache entries synchronization across application instances by means of the SetServiceBusCompanion.<br>
HowTo: Configure SmartCache synchronization across application instances
cacheServiceload your data by means of Diginsight.SmartCache cacheService
[HttpGet("getplantscached", Name = "GetPlantsCachedAsync")]
[ApiVersion(ApiVersions.V_2024_04_26.Name)]
public async Task<IEnumerable<Plant>> GetPlantsCachedAsync()
{
using var activity = Program.ActivitySource.StartMethodActivity(logger);
// defines a key for the cache entry
// NB. the cache key should include all imput parameters (that may cause different responses)
// in this case the key is defined as a record including all relevant input parameters
var cacheKey = new MethodCallCacheKey(cacheKeyService,
typeof(PlantsController), nameof(GetPlantsCachedAsync));
// data with max-age 10 minutes is requested
var options = new SmartCacheOperationOptions() { MaxAge = TimeSpan.FromSeconds(600) };
// Calls GetPlantsAsync by means of smartCache service
var plants = await smartCache.GetAsync(cacheKey,
_ => GetPlantsAsync(),
options);
activity.SetOutput(plants);
return plants;
}
the image below show the log of the SampleWebApi GetPlantsCachedAsync method.<br>
The first call finds a cache miss and resolves to calling the GetPlantsAsync method.
the following calla find a cache miss obtaining the result in 2/3ms instead of more than 1sec (about 1 to 1000 ratio).
The following articles discuss the details of Diginsight.SmartCache use and configuration:
<br> discusses how to cache calls, and add support for invalidation and reload to cached data.
.<br> discusses how to configure the ServiceBusCompanion or the KubernetesCompanion to support distributed cache entries across application instances.
.<br> discusses how to configure cache size, expiration latencies and connection to external RedIs backing storage.
.<br> discusses how performance of our applications can be boosted by using smartcache.
[HowTo: Enable data preloading by means of AI assisted algorithms.md]<br> (TODO): explores how to enable AI assisted preloading to improve data preloading efficiency.<br><br>
For more information visit: SmartCache
Contribute to the repository with your pull requests.
See the file for license rights and limitations (MIT).
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 is compatible. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 is compatible. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 2 NuGet packages that depend on Diginsight.SmartCache.Externalization.Http:
| Package | Downloads |
|---|---|
|
Diginsight.SmartCache.Externalization.AspNetCore
Package Description |
|
|
Diginsight.SmartCache.Externalization.Kubernetes
Package Description |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.7.1.13 | 266 | 5/18/2026 |
| 3.7.1.12 | 792 | 3/6/2026 |
| 3.7.1.9 | 221 | 2/16/2026 |
| 3.7.1.7 | 236 | 1/16/2026 |
| 3.7.1.5 | 205 | 1/15/2026 |
| 3.7.1.1 | 219 | 1/6/2026 |
| 3.7.1 | 193 | 1/6/2026 |
| 3.6.0-alpha.3 | 169 | 10/6/2025 |
| 3.6.0-alpha.2 | 251 | 9/19/2025 |
| 3.6.0-alpha.1 | 238 | 9/19/2025 |
| 3.5.0 | 477 | 8/13/2025 |
| 3.3.0.1 | 390 | 6/3/2025 |
| 3.3.0 | 521 | 2/3/2025 |
| 3.3.0-alpha.2 | 130 | 2/3/2025 |
| 3.3.0-alpha.1 | 120 | 1/29/2025 |
| 3.2.1 | 1,457 | 11/15/2024 |
| 3.2.0 | 274 | 11/15/2024 |
| 3.1.0.1 | 387 | 10/31/2024 |
| 3.1.0 | 299 | 10/11/2024 |