From 03fbe92c7f5025df11a561d001fdc43dccecd5d1 Mon Sep 17 00:00:00 2001 From: Ethan Wellenreiter Date: Tue, 6 May 2025 23:50:45 -0400 Subject: [PATCH] Adding expiration times and interface for cached items Signed-off-by: Ethan Wellenreiter --- backend/internal/storage/cache/cache.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/backend/internal/storage/cache/cache.go b/backend/internal/storage/cache/cache.go index 83dd65f..95c9634 100644 --- a/backend/internal/storage/cache/cache.go +++ b/backend/internal/storage/cache/cache.go @@ -2,17 +2,42 @@ package cache import ( "context" + "time" "git.ewellenr.ca/receipt_indexer/backend/internal/storage" // auth_storage "git.ewellenr.ca/receipt_indexer/backend/internal/storage/auth" ) +const ( + UserExpTime = time.Minute + RolesExpTime = time.Minute + GroupsExpTime = time.Minute + UserGroupsExpTime = time.Minute + ReceptsExpTime = time.Minute + ReceiptImageExpTime = time.Minute +) + type Storage struct { Users interface { Get(ctx context.Context, id int64) (*storage.User, error) Set(ctx context.Context, user *storage.User) error Delete(ctx context.Context, userID int64) } + Roles interface { + Get(ctx context.Context, name string) (*storage.Role, error) + Set(ctx context.Context, role *storage.Role) error + Delete(ctx context.Context, name string) + } + Groups interface { + Get(ctx context.Context, name string) (*storage.Role, error) + Set(ctx context.Context, role *storage.Role) error + Delete(ctx context.Context, name string) + } + UserGroups interface { + Get(ctx context.Context, userid int64) (*[]int64, error) + Set(ctx context.Context, groups *[]int64) error + Delete(ctx context.Context, userid int64) + } Receipts interface { Get(ctx context.Context, id int64) (*storage.Receipt, error) Set(ctx context.Context, receipt *storage.Receipt) error