Skip to content

Implement Flexible Cache Configuration Options#8

Open
Vuk7912 wants to merge 5 commits into
Merango:f5ee4aa2-87d6-43d4-a6ce-98204349da10from
Vuk7912:feature-cache-config-options-1749230398
Open

Implement Flexible Cache Configuration Options#8
Vuk7912 wants to merge 5 commits into
Merango:f5ee4aa2-87d6-43d4-a6ce-98204349da10from
Vuk7912:feature-cache-config-options-1749230398

Conversation

@Vuk7912
Copy link
Copy Markdown

@Vuk7912 Vuk7912 commented Jun 6, 2025

Implement Flexible Cache Configuration Options

Description

Task

Implement cache configuration options

Acceptance Criteria

  • Cache configuration interface supports all NodeCache configuration options
  • createCache() function allows complete customization of cache behavior
  • Default cache configuration remains unchanged
  • Input validation prevents invalid configuration parameters
  • New configuration options do not break existing code
  • Performance overhead of configuration is minimal

Summary of Work

Overview

This pull request adds comprehensive, flexible configuration options for the caching mechanism, allowing fine-tuned control over caching behavior in the application.

Changes Implemented

  • Enhanced CacheConfig interface to support more detailed cache configuration
  • Added robust validation for cache configuration parameters
  • Created a flexible createCache() function that allows deep customization
  • Maintained backward compatibility with existing default configuration

Key Features

  • Configurable Time-to-Live (TTL) for cached items
  • Adjustable key expiration check period
  • Maximum key limit configuration
  • Object cloning toggle
  • Comprehensive input validation

Configuration Options

  • stdTTL: Standard time-to-live for cache entries (in seconds)
  • checkperiod: Interval for checking and removing expired keys
  • maxKeys: Maximum number of keys to store in cache
  • useClones: Whether to create clones of stored objects

Example Usage

// Default cache (no changes)
const defaultCache = createCache();

// Custom cache with specific configuration
const customCache = createCache({
  stdTTL: 300,        // 5-minute cache duration
  checkperiod: 60,    // Check for expired keys every minute
  maxKeys: 500,       // Limit to 500 keys
  useClones: false    // Disable object cloning for performance
});

Validation Improvements

  • Prevents negative TTL values
  • Ensures maxKeys is a positive number
  • Provides clear error messages for invalid configurations

Performance Considerations

  • Minimal overhead for configuration
  • Flexible caching strategy
  • Optional object cloning for memory efficiency

Testing

  • Validated default configuration behavior
  • Tested custom configuration scenarios
  • Verified input validation logic
  • Ensured no breaking changes to existing implementations

Changes Made

  • Enhanced CacheConfig interface in src/config/cache.ts
  • Added comprehensive input validation for cache parameters
  • Created flexible createCache() function with custom configuration support
  • Maintained default cache configuration with no-config instantiation
  • Updated type definitions to support more detailed cache configuration

Tests

  • Verify default cache configuration creates correct NodeCache instance
  • Test custom configuration overrides default settings
  • Validate input validation for invalid TTL and maxKeys values
  • Ensure object cloning can be toggled via configuration
  • Check that custom cache instances have correct configuration parameters

Signatures

Staking Key

3oBzgQ4y8YtmkxYGkse1fKKefi25twpMKU9BBdsYtjDQ: 4vmvBQYEG9KtNf9AQyaXCVMAX7FYkiohD3CqZpviYHyNNp65fJhi7UepDPcaWiGUF6F9SieHPUcSdKMSzFJVcrhMgVU8xhr4mA67fxT3whhKmvqusZRu5c5wdtsRhEx4wMEQ3JUX5PSZHmEQgXRdE7vk3yq6Sp41Doew298ew1cxoAB55TJyjxKCzG4AZY4RKV7fsVxUdoDDuiQLMRG1G72TTbPRVEZp7DJg1BbVuQt57wXvNn818q7X5f3gq5jNoTToebJGsJCnY4M1dtbZoCmRdN1jKp8p2EGESAKeesbXdAc4DkaD9Q2yDdZdUosmTQiB7VNfKiSY9JAFjQzKWnJ7oZBq3DcL47B67e9XKYGSH3icidRK9GkHdK16uxEkBNkiuJ66boR5EqdJuF6iQi3DobAPvU

Public Key

4WA5vRJLthsg6sJqVc6DQuRkGzvoxZ11SkqzwbqxCo2V: F63xqTfNtiGrTY5ryp1mKBGxEAxvQfF9Shvkz929TzLA1p8YyRQqbhGwzPRy8AfTemKfSyZcqZSwSLrhwiQN7ePxrAQNjBzS1Dd28LaRgxAdUGf67ACtXxRfu3UqFaUNkZ4cT55dbUh9iC75vbcZ4GrXKnCNzpLbHuwQ61bEi2VC7vLLcwr24w7tERKUco3LWXuTGAmSL72h4fEUVnUhDgKKJMhsM99F9RpyKjcpcxaYXM5hTts41TfVhS227sAq5phE4d3PMDgbYhnieC1pZGmMormSoKtYiNBw25pr6PkYSFAt72PEh9nBPPprYJzJLNuNVpn4W5a1XKqqZhQ6r9nfSyPoH7EjcxwfxsrcJhvw6U6fbJCdFypjt52JgzTRSZWYjqVMqupd5TTsTTHY6rLTQGXU44

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant