Skip to content
This repository was archived by the owner on Nov 16, 2025. It is now read-only.

Commit cc79333

Browse files
committed
fix: prevent UserDefaults 4MB limit crash by not caching full Claude log data
- Remove caching of full daily usage data in UserDefaults (was causing crashes) - Rely on permanent cache for individual file caching instead - Clear any existing corrupted cache data on invalidation - This fixes the "Attempting to store >= 4194304 bytes" error The permanent cache system already handles individual file caching efficiently, so there's no need to also cache the aggregated daily usage in UserDefaults.
1 parent 46f24d7 commit cc79333

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

VibeMeter/Core/Services/ClaudeLogCacheManager.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,14 @@ public final class ClaudeLogCacheManager: @unchecked Sendable {
5353
/// Get cached daily usage data
5454
public var cachedDailyUsage: [Date: [ClaudeLogEntry]]? {
5555
get {
56-
guard let data = userDefaults.data(forKey: cacheKey),
57-
let decoded = try? JSONDecoder().decode([Date: [ClaudeLogEntry]].self, from: data) else {
58-
return nil
59-
}
60-
return decoded
56+
// Don't cache full daily usage in UserDefaults - it's too large
57+
// Rely on permanent cache for individual files instead
58+
return nil
6159
}
6260
set {
63-
if let newValue,
64-
let encoded = try? JSONEncoder().encode(newValue) {
65-
userDefaults.set(encoded, forKey: cacheKey)
66-
} else {
67-
userDefaults.removeObject(forKey: cacheKey)
68-
}
61+
// Don't store in UserDefaults to avoid 4MB limit
62+
// The permanent cache handles individual file caching
63+
logger.debug("Skipping UserDefaults cache for daily usage (too large)")
6964
}
7065
}
7166

@@ -275,14 +270,19 @@ public final class ClaudeLogCacheManager: @unchecked Sendable {
275270

276271
/// Update daily usage cache
277272
public func updateDailyUsageCache(_ dailyUsage: [Date: [ClaudeLogEntry]], fileHashCache: [String: Data]) {
278-
self.cachedDailyUsage = dailyUsage
273+
// Don't cache the full daily usage - it's too large for UserDefaults
274+
// Only update the timestamp and file hash cache
279275
self.cacheTimestamp = Date()
280276
self.fileHashCache = fileHashCache
277+
278+
let totalEntries = dailyUsage.values.flatMap { $0 }.count
279+
logger.info("Processed \(totalEntries) entries, updated cache timestamp (not storing full data)")
281280
}
282281

283282
/// Invalidate all caches
284283
public func invalidateAll() {
285-
cachedDailyUsage = nil
284+
// Remove the old cache key if it exists
285+
userDefaults.removeObject(forKey: cacheKey)
286286
cacheTimestamp = nil
287287
fileHashCache = [:]
288288
currentWindowCache = nil

0 commit comments

Comments
 (0)