<commit_before>package vtls

import (
	"crypto/tls"
	"fmt"
	"net/http"
	"sync"
	"time"
)

var (
	day  = 24 * time.Hour
	year = 365 * day

	certTime = time.Minute
)

type certCache struct {
	m   map[string]*tls.Certificate
	mut *sync.RWMutex
	crt Certifier
}

func newCertCache(crt Certifier) *certCache {
	return &certCache{
		m:   map[string]*tls.Certificate{},
		mut: &sync.RWMutex{},
		crt: crt,
	}
}

func (cc *certCache) add(name string) (*tls.Certificate, error) {
	crt, err := cc.crt.Certify(name, certTime)
	if err != nil {
		return nil, err
	}

	cc.mut.Lock()
	cc.m[name] = &crt
	cc.mut.Unlock()
	return &crt, nil
}

func (cc *certCache) get(name string) (*tls.Certificate, error) {
	lkr := cc.mut.RLocker()
	lkr.Lock()<commit_msg>Add default ttl package variable<commit_after>package vtls

import (
	"crypto/tls"
	"fmt"
	"net/http"
	"sync"
	"time"
)

var (
	day  = 24 * time.Hour
	year = 365 * day

	//DefaultTTL is the default TTL the library will request for certificates
	DefaultTTL = day
)

type certCache struct {
	m   map[string]*tls.Certificate
	mut *sync.RWMutex
	crt Certifier
	ttl time.Duration
}

func newCertCache(crt Certifier) *certCache {
	return &certCache{
		m:   map[string]*tls.Certificate{},
		mut: &sync.RWMutex{},
		crt: crt,
		ttl: DefaultTTL,
	}
}

func (cc *certCache) add(name string) (*tls.Certificate, error) {
	crt, err := cc.crt.Certify(name, cc.ttl)
	if err != nil {
		return nil, err
	}

	cc.mut.Lock()
	cc.m[name] = &crt
	cc.mut.Unlock()
	return &crt, nil
}

func (cc *certCache) get(name string) (*tls.Certificate, error) {
	lkr := cc.mut.RLocker()
	lkr.Lock()
{'fraction_non_alphanumeric': 0.1502493765586035, 'fraction_numerical': 0.006234413965087282, 'mean_word_length': 3.7067448680351904, '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': '1281428', 'n_tokens_mistral': 681, 'n_tokens_neox': 664, 'n_words': 162}