Welcome to the basic CQL examples! These simple, focused examples are perfect for getting started with CQL's caching system. Each example demonstrates core concepts without complex dependencies.
Purpose: Comprehensive demonstration of CQL's advanced caching features Features:
- Basic memory cache operations (set/get/delete/exists)
- TTL (Time To Live) demonstration
- Tag-based cache invalidation
- Fragment caching with performance measurement
- Version-based invalidation
- Transaction-aware invalidation
- LRU eviction policies
- Cache statistics and performance monitoring
Run: crystal simple_cache_demo.cr
Purpose: Focused demonstration of core caching concepts Features:
- Memory cache basics
- Tag-based invalidation patterns
- Fragment caching with custom keys
- Version and transaction-aware invalidation
- Cache key building
- Performance statistics
Run: crystal simple_caching_demo.cr
Purpose: Basic Redis cache integration Features:
- Environment-based Redis configuration
- Basic Redis operations
- Cache with block execution
- Memory vs Redis performance comparison
- Batch operations
- Cache statistics
Run: crystal simple_redis_demo.cr
Prerequisites: Redis server running on localhost:6379
crystal simple_cache_demo.crThis provides a comprehensive overview of all caching features.
crystal simple_caching_demo.crFocuses on core caching patterns and strategies.
# Start Redis server first
redis-server
# Then run the Redis demo
crystal simple_redis_demo.cr- simple_cache_demo.cr - Start here for a complete overview
- simple_caching_demo.cr - Dive deeper into specific patterns
- simple_redis_demo.cr - Learn Redis integration
- Memory Caching - In-memory storage for fast access
- TTL Management - Automatic expiration of cached data
- Tag-based Invalidation - Group and invalidate related cache entries
- Fragment Caching - Cache expensive computations and blocks
- LRU Eviction - Automatic cleanup when cache is full
- Performance Monitoring - Track cache hit rates and efficiency
- Start Simple: Run
simple_cache_demo.crfirst to see all features in action - Read the Output: Each example provides detailed console output explaining what's happening
- Modify and Experiment: Try changing cache sizes, TTL values, and see the effects
- Check Statistics: Pay attention to cache hit rates and performance metrics
After mastering these basic examples, explore:
- ../caching/ - Advanced caching patterns and strategies
- ../blog/ - Real-world application with caching integration
- ../performance/ - Performance monitoring and optimization
Redis Connection Errors:
# Make sure Redis is running
redis-server
# Test Redis connection
redis-cli pingMissing Dependencies:
# Install required shards
shards installPerformance Issues:
- Check your system's available memory
- Monitor cache hit rates (aim for >80%)
- Adjust cache sizes based on your application needs
Ready to dive into CQL caching? Start with simple_cache_demo.cr and work your way through each example! 🚀