Cache Layer

High-performance caching for qqq applications with Redis and in-memory support.

CachingGitHub

Overview

The Cache Layer qBit provides a unified caching interface for qqq applications. It abstracts away the complexity of different caching backends while providing a consistent API.

Features

  • Multiple Backends - Redis, Memcached, and in-memory caching
  • Query Caching - Automatic caching of database query results
  • TTL Support - Configurable time-to-live for cache entries
  • Cache Invalidation - Smart invalidation on data changes
  • Metrics - Built-in cache hit/miss metrics
  • When to Use

    Use the Cache Layer qBit when you need to:

  • Reduce database load for frequently accessed data
  • Cache expensive computations
  • Share cached data across multiple application instances
  • Improve response times for read-heavy workloads
  • Installation

    Maven

    Add the following dependency to your pom.xml:

    XML
    <dependency>
        <groupId>io.qrun</groupId>
        <artifactId>qbit-cache-layer</artifactId>
        <version>2.1.0</version>
    </dependency>

    Gradle

    Groovy
    implementation 'io.qrun:qbit-cache-layer:2.1.0'

    Requirements

  • qqq 1.2.0 or higher
  • Java 17+
  • Redis 6.0+ (if using Redis backend)
  • Configuration

    Redis Backend

    YAML
    cache:
      backend: redis
      redis:
        host: localhost
        port: 6379
        password: ${REDIS_PASSWORD}
        database: 0
        ssl: true

    In-Memory Backend

    YAML
    cache:
      backend: memory
      memory:
        maxSize: 10000
        expireAfterWrite: 3600

    Configuration Options

    OptionDefaultDescription
    backendmemoryCache backend (redis, memory)
    defaultTtl3600Default TTL in seconds
    keyPrefixqqq:Prefix for cache keys

    API Reference

    CacheService

    The main interface for cache operations.

    Java
    @Inject
    private CacheService cacheService;
    
    // Get from cache
    Optional<Customer> customer = cacheService.get("customer:123", Customer.class);
    
    // Put in cache
    cacheService.put("customer:123", customer, Duration.ofMinutes(5));
    
    // Delete from cache
    cacheService.delete("customer:123");

    Annotations

    Java
    @Cacheable(key = "customer:#{id}", ttl = 300)
    public Customer getCustomer(Integer id) {
        // Method implementation
    }

    Knowledge Base

    Powered by qqq