1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/// Code churn cache strategy with Git commit tracking.
///
/// Caches code churn analysis results and automatically invalidates when the
/// Git HEAD commit changes. Uses Git SHA for precise invalidation detection.
///
/// # Cache Characteristics
///
/// - **TTL**: 30 minutes (Git data is stable)
/// - **Max Size**: 20 entries (memory-intensive)
/// - **Key**: Repository path + period + HEAD commit SHA
/// - **Validation**: HEAD commit unchanged
///
/// # Examples
///
/// ```rust,no_run
/// use pmat::services::cache::ChurnCacheStrategy;
/// use pmat::services::cache::CacheStrategy;
/// use pmat::models::churn::CodeChurnAnalysis;
/// use std::path::PathBuf;
/// use tempfile::tempdir;
///
/// let strategy = ChurnCacheStrategy;
/// let repo_dir = tempdir().expect("tempdir");
/// let key = (repo_dir.path().to_path_buf(), 30); // 30 days
///
/// // Generate cache key (includes Git HEAD)
/// let cache_key = strategy.cache_key(&key);
/// assert!(cache_key.starts_with("churn:"));
/// assert!(cache_key.contains(":30:"));
///
/// // Create a dummy churn analysis
/// let churn = CodeChurnAnalysis {
/// generated_at: chrono::Utc::now(),
/// period_days: 30,
/// repository_root: repo_dir.path().to_path_buf(),
/// files: vec![],
/// summary: pmat::models::churn::ChurnSummary {
/// total_commits: 0,
/// total_files_changed: 0,
/// hotspot_files: vec![],
/// stable_files: vec![],
/// author_contributions: std::collections::HashMap::new(),
/// mean_churn_score: 0.0,
/// variance_churn_score: 0.0,
/// stddev_churn_score: 0.0,
/// },
/// };
///
/// // Validation depends on Git state
/// // let is_valid = strategy.validate(&key, &churn);
///
/// // TTL should be 30 minutes
/// assert_eq!(strategy.ttl().expect("has ttl").as_secs(), 1800);
/// assert_eq!(strategy.max_size(), 20);
/// ```
/// Git statistics cache strategy for repository metadata.
///
/// Caches Git repository statistics (commits, authors, branches) with validation
/// based on HEAD commit SHA. Provides fast access to repository metadata.
///
/// # Cache Characteristics
///
/// - **TTL**: 15 minutes
/// - **Max Size**: 10 entries
/// - **Key**: Repository path + current branch
/// - **Validation**: HEAD commit unchanged
///
/// # Examples
///
/// ```rust,no_run
/// use pmat::services::cache::{GitStatsCacheStrategy, GitStats, CacheStrategy};
/// use std::path::PathBuf;
/// use tempfile::tempdir;
///
/// let strategy = GitStatsCacheStrategy;
/// let repo_dir = tempdir().expect("tempdir");
///
/// // Generate cache key
/// let cache_key = strategy.cache_key(&repo_dir.path().to_path_buf());
/// assert!(cache_key.starts_with("git_stats:"));
///
/// // Create sample Git stats
/// let stats = GitStats {
/// total_commits: 42,
/// authors: vec!["alice".to_string(), "bob".to_string()],
/// branch: "main".to_string(),
/// head_commit: "abc123".to_string(),
/// };
///
/// // Validation depends on Git HEAD
/// // let is_valid = strategy.validate(&repo_dir.path().to_path_buf(), &stats);
///
/// // TTL should be 15 minutes
/// assert_eq!(strategy.ttl().expect("has ttl").as_secs(), 900);
/// assert_eq!(strategy.max_size(), 10);
/// ```