Skip to content

Commit f364802

Browse files
authored
Merge pull request #33 from iazaran/cost-aware-caching-and-fixes
Cost aware caching and fixes
2 parents 3ee0760 + 473fd2a commit f364802

16 files changed

+1445
-855
lines changed

README.md

Lines changed: 145 additions & 488 deletions
Large diffs are not rendered by default.

TESTING.md

Lines changed: 1 addition & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -47,56 +47,6 @@ composer test-coverage
4747
# Generates HTML coverage report in ./coverage/ directory
4848
```
4949

50-
### Test New Features
51-
```bash
52-
# Test Laravel 12 SWR methods
53-
vendor/bin/phpunit tests/Unit/Laravel12/Laravel12SWRTest.php
54-
55-
# Test HTTP command execution
56-
vendor/bin/phpunit tests/Unit/Http/HttpCommandExecutionTest.php
57-
58-
# Test performance monitoring
59-
vendor/bin/phpunit tests/Unit/Monitoring/PerformanceMonitoringTest.php
60-
61-
# Test complete feature integration
62-
vendor/bin/phpunit tests/Feature/EnhancedSmartCacheControllerTest.php
63-
```
64-
65-
## New Enhanced Features Testing
66-
67-
SmartCache v1.5+ includes comprehensive testing for new enterprise features:
68-
69-
### Laravel 12 SWR Methods Testing
70-
- **SWR (Stale-While-Revalidate)** pattern validation
71-
- **Stale serving** with extended TTL support
72-
- **Refresh-ahead** proactive caching
73-
- **Flexible caching** with custom duration arrays
74-
- **Cross-compatibility** between facade and helper methods
75-
- **Optimization integration** with SWR patterns
76-
77-
### HTTP Command Execution Testing
78-
- **Command discovery** and metadata retrieval
79-
- **Programmatic execution** of cache commands
80-
- **Parameter handling** and validation
81-
- **Error handling** and graceful failures
82-
- **Security validation** for non-managed keys
83-
- **Facade integration** for HTTP commands
84-
85-
### Performance Monitoring Testing
86-
- **Metrics collection** for hits, misses, and writes
87-
- **Cache efficiency** calculation and reporting
88-
- **Optimization impact** tracking and analysis
89-
- **Performance analysis** with automated recommendations
90-
- **Metrics persistence** across application instances
91-
- **Dashboard integration** capabilities
92-
93-
### Integration Testing
94-
- **Real-world scenarios** like e-commerce platforms
95-
- **Multi-pattern usage** combining SWR methods
96-
- **Performance monitoring integration** with caching operations
97-
- **HTTP command execution** in application context
98-
- **Complete feature workflows** from cache to monitoring
99-
10050
## Testing Best Practices
10151

10252
When contributing to SmartCache, follow these testing guidelines:
@@ -129,59 +79,6 @@ php8.2 vendor/bin/phpunit
12979
php8.3 vendor/bin/phpunit
13080
```
13181

132-
## Test Structure
133-
134-
SmartCache maintains **comprehensive test coverage** with **252 tests** organized for maintainability:
135-
136-
```
137-
tests/
138-
├── bootstrap.php # Test bootstrap (sets up environment)
139-
├── TestCase.php # Base test class with common utilities
140-
├── Unit/ # Unit tests (isolated component testing)
141-
│ ├── SmartCacheTest.php # Core SmartCache functionality
142-
│ ├── Console/ # Console command tests
143-
│ │ ├── ClearCommandTest.php
144-
│ │ └── StatusCommandTest.php
145-
│ ├── Http/ # HTTP-related tests
146-
│ │ └── HttpCommandExecutionTest.php # HTTP command execution
147-
│ ├── Laravel12/ # Laravel 12+ features
148-
│ │ └── Laravel12SWRTest.php # SWR methods (swr, stale, refreshAhead)
149-
│ ├── Monitoring/ # Performance monitoring
150-
│ │ └── PerformanceMonitoringTest.php
151-
│ ├── Providers/ # Service provider tests
152-
│ │ └── SmartCacheServiceProviderTest.php
153-
│ ├── Services/ # Service tests
154-
│ │ └── CacheInvalidationServiceTest.php
155-
│ ├── Strategies/ # Strategy tests
156-
│ │ ├── CompressionStrategyTest.php
157-
│ │ └── ChunkingStrategyTest.php
158-
│ ├── Traits/ # Trait tests
159-
│ │ └── ModelIntegrationTest.php
160-
│ ├── DependencyTrackingTest.php
161-
│ ├── PatternBasedInvalidationTest.php
162-
│ ├── StrategyOrderingTest.php
163-
│ └── TagBasedInvalidationTest.php
164-
├── Feature/ # Integration tests
165-
│ ├── SmartCacheIntegrationTest.php
166-
│ ├── AdvancedInvalidationIntegrationTest.php
167-
│ └── EnhancedSmartCacheControllerTest.php # Full feature integration
168-
└── Fixtures/ # Test fixtures and data
169-
```
170-
171-
## Test Categories
172-
173-
### Unit Tests
174-
- Test individual components in isolation
175-
- Use mocks to avoid external dependencies
176-
- Fast execution
177-
- Located in `tests/Unit/`
178-
179-
### Feature Tests
180-
- Test complete workflows and integration
181-
- Use real Laravel components
182-
- Test the package as end users would use it
183-
- Located in `tests/Feature/`
184-
18582
## Key Testing Features
18683

18784
### 1. Orchestra Testbench Integration
@@ -358,4 +255,4 @@ class MyIntegrationTest extends TestCase
358255
- Use smaller test datasets when possible
359256
- Clean up test data in tearDown methods
360257

361-
This testing setup ensures your SmartCache package works correctly across different environments without requiring a full Laravel installation.
258+

config/smart-cache.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,22 @@
110110
'log_errors' => true,
111111
],
112112

113+
/*
114+
|--------------------------------------------------------------------------
115+
| Cost-Aware Caching
116+
|--------------------------------------------------------------------------
117+
|
118+
| Enable cost-aware caching to track the "value" of each cached key based on
119+
| regeneration cost, access frequency, and size. This allows SmartCache to
120+
| provide intelligent eviction suggestions and value-based scoring.
121+
|
122+
*/
123+
'cost_aware' => [
124+
'enabled' => true,
125+
'max_tracked_keys' => 1000, // Maximum number of keys to track metadata for
126+
'metadata_ttl' => 86400, // How long to keep cost metadata (seconds)
127+
],
128+
113129
/*
114130
|--------------------------------------------------------------------------
115131
| Performance Monitoring

0 commit comments

Comments
 (0)