This repository contains a cache microservice built using the ServiceBricks foundation. The cache microservice exposes a key/value pair object that can be used for simple data storage. It also provides a background task for an expiration process to delete cache items once their expiration date occurs.
Key and Value pair storage object along with an expiration date to denote when it can be deleted.
public partial class CacheDataDto : DataTransferObject
{
public string Key { get; set; }
public DateTimeOffset CreateDate { get; set; }
public DateTimeOffset UpdateDate { get; set; }
public DateTimeOffset? ExpirationDate { get; set; }
public string Value { get; set; }
}
- DomainCreateUpdateRule - CreateDate and UpdateDate property
- DateTimeOffsetRule - ExpirationDate property
- ApiConcurrencyByUpdateRule - UpdateDate property
This background timer runs by default every 30 minutes, with an initial delay of 30 minutes. Executes the CacheExpirationTask.
This background task queries for all CacheData whos expiration date is less than now, then deletes those records.
None
None
None
This class was initially designed to be used as a semaphore when deploying load-balanced applications so that only one server would process a background task at a time. This is because not all storage providers provide a way to lock the underlying data store and use it as a queue, so that multiple, simultaneous connections do not return the same records.
The implementation currently uses the IApiService which would require the Cache service to be hosted along with the microservice that uses this. It should be changed to support IApiClient, so that other microservices can make a client call instead of hosting the complete service. Enhancement
None
ServiceBricks is the cornerstone for building a microservices foundation. Visit http://ServiceBricks.com to learn more.