<commit_before>package api

import (
	"fmt"
	"sync"

	"github.com/boilingrip/boiling-api/db"
)

type SyncedLookupTable struct {
	l LookupTable
	sync.RWMutex
}

type Cache struct {
	formats           *SyncedLookupTable
	leechTypes        *SyncedLookupTable
	media             *SyncedLookupTable
	releaseGroupTypes *SyncedLookupTable
	releaseProperties *SyncedLookupTable
	releaseRoles      *SyncedLookupTable
	privileges        *SyncedLookupTable
}

func NewCache(db db.BoilingDB) (Cache, error) {
	c := Cache{
		formats:           new(SyncedLookupTable),
		leechTypes:        new(SyncedLookupTable),<commit_msg>api/cache: add convenience methods<commit_after>package api

import (
	"fmt"
	"sync"

	"github.com/boilingrip/boiling-api/db"
)

type SyncedLookupTable struct {
	l LookupTable
	sync.RWMutex
}

func (s *SyncedLookupTable) MustLookUp(ss string) int {
	i, err := s.LookUp(ss)
	if err != nil {
		panic(fmt.Sprintf("Key not found, cache out of sync? %s", err.Error()))
	}
	return i
}

func (s *SyncedLookupTable) LookUp(ss string) (int, error) {
	s.RLock()
	i, err := s.l.LookUp(ss)
	s.RUnlock()
	return i, err
}

func (s *SyncedLookupTable) MustReverseLookUp(i int) string {
	ss, err := s.ReverseLookUp(i)
	if err != nil {
		panic(fmt.Sprintf("Key not found, cache out of sync? %s", err.Error()))
	}
	return ss
}

func (s *SyncedLookupTable) ReverseLookUp(i int) (string, error) {
	s.RLock()
	ss, err := s.l.ReverseLookUp(i)
	s.RUnlock()
	return ss, err
}

func (s *SyncedLookupTable) Has(ss string) bool {
	s.RLock()
	has := s.l.Has(ss)
	s.RUnlock()
	return has
}

func (s *SyncedLookupTable) HasReverse(i int) bool {
	s.RLock()
	has := s.l.HasReverse(i)
	s.RUnlock()
	return has
}

type Cache struct {
	formats           *SyncedLookupTable
	leechTypes        *SyncedLookupTable
	media             *SyncedLookupTable
	releaseGroupTypes *SyncedLookupTable
	releaseProperties *SyncedLookupTable
	releaseRoles      *SyncedLookupTable
	privileges        *SyncedLookupTable
}

func NewCache(db db.BoilingDB) (Cache, error) {
	c := Cache{
		formats:           new(SyncedLookupTable),
		leechTypes:        new(SyncedLookupTable),
{'fraction_non_alphanumeric': 0.1136150234741784, 'fraction_numerical': 0.0, 'mean_word_length': 3.704194260485651, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1008014', 'n_tokens_mistral': 818, 'n_tokens_neox': 783, 'n_words': 182}