package models

import "sync"

type Cache struct {
	Data map[string]any
	Mu   sync.RWMutex
}

func CacheInit() *Cache {
	return &Cache{Data: make(map[string]any)}
}

func (c *Cache) Get(key string) (any, bool) {
	c.Mu.RLock()
	pageData, ok := c.Data[key]
	c.Mu.RUnlock()
	return pageData, ok
}

func (c *Cache) Set(key string, data any) {
	c.Mu.Lock()
	c.Data[key] = data
	c.Mu.Unlock()
}