Go to Redis Releases to
download the .msi for the latest release on that link if you're getting
No connection could be made because the target machine actively refused it 127.0.0.1:6379
<add key="Clarity.Ecommerce.Redis.Enabled" value="true" />
<add key="Clarity.Ecommerce.Redis.Host" value="localhost:6379" />
<add key="Clarity.Ecommerce.Redis.CacheForXMinutes" value="20" />
private async void ClearCachedXXXXData()
{
var keysToClear = new List<string>
{
UrnId.Create<XXXXX>(""),
};
foreach (var key in keysToClear)
{
await TaskFactory.StartNew(() => ClearCache(RootUrl + ":" + key));
}
}
ORIGINAL
[Route("/XXXXs/", "POST", Summary = @"Use to get a list of XXXX")]
public class GetXXXX : XXXXSearchModel, IReturn<List<XXXXModel>> { }
CACHED COPY
[Route("/XXXXs/Cached", "POST", Summary = @"Use to get a list of XXXX (will returned cached data if available)")]
public class GetXXXXCached : GetXXXX { }
ORIGINAL
public List<XXXXModel> Post(GetXXXX request) { return Workflows.XXXXs.Search(request)?.Cast<XXXXModel>().ToList(); }
CACHED COPY
public object Post(GetXXXXCached request) { return CreateAndReturnCachedResult(request, () => Post((GetXXXX)request)); }
You can now call for a cached copy, but we need to clear cached results
when things change
ORIGINAL
public XXXXModel Any(CreateXXXX request) { return (XXXXModel)Workflows.XXXXs.Create(request); }
CACHE CLEARING MODIFICATIONS
public XXXXModel Any(CreateXXXX request) { return DoClearCacheActionAndReturnResult(ClearCachedXXXXData, () => (XXXXModel)Workflows.XXXXs.Create(request)); }
This will perform the original action, then run the Clear Cache function
we added to clear the specific caches, then return the result from the
original action