<commit_before>package cache

import (
	"fmt"
	"io/ioutil"
	"os"
	"os/user"
	"path/filepath"
	"time"
)

const InternalCacheFolder string = ".bbd"

type Cache struct {
	refreshTime int
	path        string
}

func NewCache(t int) *Cache {
	cc := &Cache{
		refreshTime: t,
		path:        "/tmp/",
	}

	usr, err := user.Current()
	if err != nil {
		return cc
	}

	cc.path = usr.HomeDir +
		string(filepath.Separator) +
		InternalCacheFolder +
		string(filepath.Separator)

	_, err = os.Stat(cc.path)
	if os.IsNotExist(err) {
		if err = os.Mkdir(cc.path, 0777); err != nil {
			cc.path = "/tmp/"
		}
	}

	return cc
}

func (c *Cache) GetPath() string {
	return c.path
}

func (c *Cache) SetCache(name string, data []byte) error {
	return ioutil.WriteFile(c.path+name, data, 0644)
}

func (c *Cache) GetCache(name string) ([]byte, error) {
	f, err := os.Stat(c.path + name)
	if os.IsNotExist(err) {
		return nil, err
	}

	if time.Since(f.ModTime()).Minutes() > float64(c.refreshTime) {
		return nil, fmt.Errorf("[GetCache] %s", "cache invalidate")
	}

	dat, err := ioutil.ReadFile(c.path + name)
	if err != nil {
		return nil, err
	}
	return dat, nil
}
<commit_msg>seems that the cache package still faliling on freebsd<commit_after>package cache

import (
	"fmt"
	"io/ioutil"
	"os"
	"os/user"
	"time"
)

const InternalCacheFolder string = ".bbd/"

type Cache struct {
	refreshTime int
	path        string
}

func NewCache(t int) *Cache {
	cc := &Cache{
		refreshTime: t,
		path:        "/tmp/",
	}

	usr, err := user.Current()
	if err != nil {
		return cc
	}

	cc.path = usr.HomeDir + "/" + InternalCacheFolder

	_, err = os.Stat(cc.path)
	if os.IsNotExist(err) {
		if err = os.Mkdir(cc.path, 0777); err != nil {
			cc.path = "/tmp/"
		}
	}

	return cc
}

func (c *Cache) GetPath() string {
	return c.path
}

func (c *Cache) SetCache(name string, data []byte) error {
	return ioutil.WriteFile(c.path+name, data, 0777)
}

func (c *Cache) GetCache(name string) ([]byte, error) {
	f, err := os.Stat(c.path + name)
	if os.IsNotExist(err) {
		return nil, err
	}

	if time.Since(f.ModTime()).Minutes() > float64(c.refreshTime) {
		return nil, fmt.Errorf("[GetCache] %s", "cache invalidate")
	}

	dat, err := ioutil.ReadFile(c.path + name)
	if err != nil {
		return nil, err
	}
	return dat, nil
}

{'fraction_non_alphanumeric': 0.1601750547045952, 'fraction_numerical': 0.0087527352297593, 'mean_word_length': 3.2333333333333334, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '862109', 'n_tokens_mistral': 971, 'n_tokens_neox': 924, 'n_words': 233}