package cache import ( "iter" "time" ) // RecordStore handles record persistence operations. // Iterator methods use iter.Seq2 for iteration, with keys and values // cloned to memory to avoid holding read locks during iteration. type RecordStore interface { // SaveRecords stores records for a given DID. SaveRecords(did string, records map[string][]byte) error // IterateUnpublished iterates over unpublished records. // The iterator yields (key, record) pairs. // If reverse is true, iterates in reverse order using Cursor.Last/Cursor.Prev. IterateUnpublished(did string, reverse bool) iter.Seq2[string, []byte] // IteratePublished iterates over published records. // The iterator yields (key, record) pairs. // If reverse is true, iterates in reverse order using Cursor.Last/Cursor.Prev. IteratePublished(did string, reverse bool) iter.Seq2[string, []byte] // IterateFailed iterates over failed records. // Returns a function that yields (key, record, errorMessage) triples. IterateFailed(did string) func(yield func(key string, rec []byte, errMsg string) bool) MarkPublished(did string, keys ...string) error MarkFailed(did string, keys []string, err string) error RemoveFailed(did string, keys ...string) error GetPublished(did string) (map[string]bool, error) Clear(did string) error Close() error } // QuotaStore handles rate limit quota tracking. type QuotaStore interface { GetMulti(keys []string) (map[string]int, error) IncrByMulti(counts map[string]int) error } // Storage combines RecordStore and QuotaStore interfaces. // Provided for backwards compatibility. type Storage interface { RecordStore QuotaStore IsValid(did string) bool Timestamp(did string) (time.Time, error) ClearAll() error // Stats returns database statistics Stats() (DBStats, error) } type DBStats struct { TotalRecords int `json:"totalRecords"` MarkedPublished int `json:"markedPublished"` FailedCount int `json:"failedCount"` UnpublishedCount int `json:"unpublishedCount"` UserStats map[string]any `json:"userStats"` }