Eiffel
  • Overview
    • About
  • Features
    • Cross cutting concerns
      • API response consistency
      • Global exception handling
      • Idempotency
      • Audit logging
    • Caching
      • Configuration
        • In-Memory
        • Redis
      • Usage
      • API
        • CacheSource
        • InMemoryCacheOptions
        • RedisCacheOptions
        • ICacheService
        • ICacheServiceFactory
    • Localization
    • Job Processing
    • Multi-Tenancy
    • Metrics & monitoring
    • Transactional outbox
      • PostgreSQL
      • MongoDB (cluster only)
    • Messaging
      • Kafka
      • Rabbit MQ
      • Azure Service Bus
    • Awaitable socket client
    • Graceful shutdown
  • Fundamentals
    • Persistence
    • Modelling
  • Principles
    • Domain-Driven Design
      • Aggregates
      • Entities
      • Value Objects
      • Domain Events
      • Factories
      • Domain Services
      • Business Identifiers
      • Shared Kernel
    • Onion Architecture
      • Application Layer
      • Domain Layer
      • Infrastructure Layer
      • Anti-Corruption Layer
    • Modular Monolith Architecture
      • Modules
      • Shared Infrastructure
    • Microservice Architecture
      • API Gateway
      • View Model Composition
      • Contracts
  • Business Aligment
    • Domain Storytelling
    • User stories
  • Implementation
    • Modular Monolith
    • Microservices
  • Testing
    • Unit Testing
    • Integration Testing
    • Contract Testing
  • Cloud Infrastructure
    • CI/CD Pipelines
    • Docker
    • Kubernates
    • Infrastructure as Code
Powered by GitBook
On this page
  1. Features

Caching

The ICacheService interface defines a standard set of operations for caching mechanisms. It provides methods for asynchronous and synchronous retrieval and storage of cache items, allowing for both timespan-based and datetime-offset-based expiration. Additionally, it offers a mechanism to verify the existence of a specific cache key. Implement this interface to create consistent caching providers for different storage backends.

/// <summary>
/// Common cache provider interface
/// </summary>
public interface ICacheService
{
    /// <summary>
    /// Gets cache value
    /// </summary>
    /// <typeparam name="T">The type of result object</typeparam>
    /// <param name="cacheKey">Cache key</param>
    /// <returns>Object</returns>
    T Get<T>(string cacheKey);
    
    /// <summary>
    /// Gets cache value asynchronous
    /// </summary>
    /// <typeparam name="T">The type of result object</typeparam>
    /// <param name="cacheKey">Cache key</param>
    /// <returns>Object</returns>
    Task<T> GetAsync<T>(string cacheKey);
    
    /// <summary>
    /// Sets cache value asynchronous
    /// </summary>
    /// <typeparam name="T">The type of source object</typeparam>
    /// <param name="cacheKey">Cache key</param>
    /// <param name="value">Object value</param>
    /// <param name="expiresIn">Expires after given value</param>
    void Set<T>(string cacheKey, T value, TimeSpan? expiresIn = null);
    
    /// <summary>
    /// Sets cache value asynchronous
    /// </summary>
    /// <typeparam name="T">The type of source object</typeparam>
    /// <param name="cacheKey">Cache key</param>
    /// <param name="value">Object value</param>
    /// <param name="expiresIn">Expires after given value</param>
    Task SetAsync<T>(string cacheKey, T value, TimeSpan? expiresIn = null);
    
    /// <summary>
    /// Sets cache value synchronous
    /// </summary>
    /// <typeparam name="T">The type of source object</typeparam>
    /// <param name="cacheKey">Cache key</param>
    /// <param name="value">Object value</param>
    /// <param name="expiresOn">Expires on given date time offset</param>
    void Set<T>(string cacheKey, T value, DateTimeOffset expiresOn);
    
    /// <summary>
    /// Sets cache value asynchronous
    /// </summary>
    /// <typeparam name="T">The type of source object</typeparam>
    /// <param name="cacheKey">Cache key</param>
    /// <param name="value">Object value</param>
    /// <param name="expiresOn">Expires on given date time offset</param>
    Task SetAsync<T>(string cacheKey, T value, DateTimeOffset expiresOn);
    
    /// <summary>
    /// Removes cache key
    /// </summary>
    /// <param name="cacheKey">Cache key</param>
    void Delete(string cacheKey);
    
    /// <summary>
    /// Removes cache key
    /// </summary>
    /// <param name="cacheKey">Cache key</param>
    Task DeleteAsync(string cacheKey);

    /// <summary>
    /// Checks given key is exist in cache or not
    /// </summary>
    /// <param name="cacheKey">Cache key</param>
    /// <returns>true/false</returns>
    bool IsExists(string cacheKey);
}

PreviousAudit loggingNextConfiguration

Last updated 1 year ago