Skip to main content

rs_claude_bar/cache/
types.rs

1use std::collections::HashMap;
2use chrono::{DateTime, Utc};
3use serde::{Deserialize, Serialize};
4
5// represent the cache information in .claude_bar/cache.json
6#[derive(Debug, Clone, Serialize, Deserialize)]
7#[serde(transparent)]
8pub struct CacheInfo {
9    pub folders: HashMap<String, CachedFolder>
10}
11impl Default for CacheInfo {
12    fn default() -> Self { CacheInfo { folders: HashMap::new() } }
13}
14
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
17pub struct CachedFolder {
18    pub files: HashMap<String, CachedFile>,
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
22pub struct CachedFile {
23    pub file_name: String,
24    pub cache_time: DateTime<Utc>,   //Use as cache date
25    /// Map of limit/unlock events keyed by block timestamp
26    pub blocks: HashMap<DateTime<Utc>, BlockLine>,
27    /// Map of hourly usage summaries (hour_start -> PerHourBlock) for O(1) lookup
28    pub per_hour: HashMap<DateTime<Utc>, PerHourBlock>,
29    #[serde(skip)]
30    pub cache_status: CacheStatus,
31    #[serde(skip)]
32    pub modified_time: DateTime<Utc>,
33    #[serde(skip)]
34    pub created_time: DateTime<Utc>,
35    #[serde(skip)]
36    pub size_bytes: u64,
37}
38
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
41pub struct BlockLine {
42    /// Timestamp when the block was lifted/reset (if available)
43    pub unlock_timestamp: Option<DateTime<Utc>>,
44    /// Human-readable reset time (e.g. "5pm", "2h30m")
45    pub reset_text: String,
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
49pub struct PerHourBlock {
50    /// Start of the hour block (e.g. 01:00:00)
51    pub hour_start: DateTime<Utc>,
52    /// End of the hour block (e.g. 01:59:59)  
53    pub hour_end: DateTime<Utc>,
54    /// Minimum timestamp found in this hour
55    pub min_timestamp: DateTime<Utc>,
56    /// Maximum timestamp found in this hour  
57    pub max_timestamp: DateTime<Utc>,
58    /// Total input tokens used in this hour
59    pub input_tokens: u32,
60    /// Total output tokens used in this hour
61    pub output_tokens: u32,
62    /// Total cache creation tokens in this hour
63    pub cache_creation_tokens: u32,
64    /// Total cache read tokens in this hour
65    pub cache_read_tokens: u32,
66    /// Number of assistant messages in this hour
67    pub assistant_messages: u32,
68    /// Number of user messages in this hour
69    pub user_messages: u32,
70    /// Total content length of all messages in this hour
71    pub total_content_length: u64,
72    /// Number of entries processed in this hour
73    pub entry_count: u32,
74}
75
76#[derive(Debug, Clone)]
77pub enum CacheStatus {
78    Fresh,           // File in cache and up-to-date
79    NeedsRefresh,    // File modified since cache date
80    NotInCache,      // File not in cache yet
81}
82impl Default for CacheStatus {
83    fn default() -> Self { CacheStatus::NotInCache }
84}