Caching
Fast, consistent caching with InMemory, Redis, and Hybrid implementations. Includes scoped cache support.
Pluggable foundation blocks for building loosely coupled distributed applications
using Foundatio.Caching;
ICacheClient cache = new InMemoryCacheClient();
await cache.SetAsync("test", 1);
var value = await cache.GetAsync<int>("test");using Foundatio.Queues;
IQueue<SimpleWorkItem> queue = new InMemoryQueue<SimpleWorkItem>();
await queue.EnqueueAsync(new SimpleWorkItem { Data = "Hello" });
var workItem = await queue.DequeueAsync();using Foundatio.Lock;
ILockProvider locker = new CacheLockProvider(
new InMemoryCacheClient(),
new InMemoryMessageBus()
);
await using var lck = await locker.AcquireAsync("resource");
if (lck is null)
throw new InvalidOperationException("Could not acquire lock");
// Do exclusive work
await ProcessAsync();using Foundatio.Messaging;
IMessageBus messageBus = new InMemoryMessageBus();
await messageBus.SubscribeAsync<SimpleMessage>(msg => {
// Got message
});
await messageBus.PublishAsync(new SimpleMessage { Data = "Hello" });using Foundatio.Storage;
IFileStorage storage = new InMemoryFileStorage();
await storage.SaveFileAsync("test.txt", "test");
string content = await storage.GetFileContentsAsync("test.txt");Learn more about File Storage →
using Foundatio.Resilience;
var policy = new ResiliencePolicyBuilder()
.WithMaxAttempts(3)
.WithExponentialDelay(TimeSpan.FromSeconds(1))
.Build();
await policy.ExecuteAsync(async ct => {
await SomeUnreliableOperationAsync(ct);
});When building several large cloud applications we found a lack of great solutions for many key pieces to building scalable distributed applications while keeping the development experience simple. Here's why we built and use Foundatio:
| Provider | Caching | Queues | Messaging | Locks | Storage |
|---|---|---|---|---|---|
| Aliyun | ✅ | ||||
| AWS | ✅ | ✅ | |||
| Azure ServiceBus | ✅ | ✅ | |||
| Azure Storage | ✅ | ✅ | |||
| In-Memory | ✅ | ✅ | ✅ | ✅ | ✅ |
| Kafka | ✅ | ||||
| Minio | ✅ | ||||
| RabbitMQ | ✅ | ||||
| Redis | ✅ | ✅ | ✅ | ✅ | ✅ |
| SshNet | ✅ |