<commit_before>package cache

import (
	"sync"
)

type Data interface{}
type Key interface{}
type GenFunc func() (Data, Stamp, error)
type Stamp interface{}

type cacheValue struct {
	stamp interface{}
	data  Data
	*sync.Mutex
}

type Cache struct {
	store map[interface{}]*cacheValue
	*sync.Mutex
}

func New() *Cache {
	return &Cache{
		store:      map[interface{}]*cacheValue{},
		sync.Mutex: &sync.Mutex{},
	}
}

func (me *Cache) Get(key Key, stamp Stamp, genfn GenFunc) (data Data, err error) {
	me.Lock()
	val, ok := me.store[key]
	if !ok {
		val = &cacheValue{
			sync.Mutex: &sync.Mutex{},
		}
		me.store[key] = val
	}
	me.Unlock()
	val.Lock()
	if val.stamp != stamp {
		val.data, val.stamp, err = genfn()
		if err != nil {
			val.stamp = nil
		}
	}
	data = val.data
	val.Unlock()
	return
}<commit_msg>Embed sync.Mutex in Cache and cacheValue<commit_after>package cache

import (
	"sync"
)

type Data interface{}
type Key interface{}
type GenFunc func() (Data, Stamp, error)
type Stamp interface{}

type cacheValue struct {
	stamp interface{}
	data  Data
	sync.Mutex
}

type Cache struct {
	store map[interface{}]*cacheValue
	sync.Mutex
}

func New() *Cache {
	return &Cache{
		store: map[interface{}]*cacheValue{},
	}
}

func (me *Cache) Get(key Key, stamp Stamp, genfn GenFunc) (data Data, err error) {
	me.Lock()
	val, ok := me.store[key]
	if !ok {
		val = &cacheValue{}
		me.store[key] = val
	}
	me.Unlock()
	val.Lock()
	if val.stamp != stamp {
		val.data, val.stamp, err = genfn()
		if err != nil {
			val.stamp = nil
		}
	}
	data = val.data
	val.Unlock()
	return
}
{'fraction_non_alphanumeric': 0.15019011406844107, 'fraction_numerical': 0.0, 'mean_word_length': 3.5635838150289016, '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': '3984635', 'n_tokens_mistral': 624, 'n_tokens_neox': 614, 'n_words': 171}