<commit_before>// Package memcache provides a Memcache Image Cache
package memcache

import (
	memcache_impl "github.com/bradfitz/gomemcache/memcache"
	"github.com/pierrre/imageserver"
)

// MemcacheCache represents a Memcache Image Cache
//
// It uses <NAME>'s Memcache client https://github.com/bradfitz/gomemcache
type MemcacheCache struct {
	Memcache *memcache_impl.Client
}

// Get gets an Image from Memcache
func (cache *MemcacheCache) Get(key string, parameters imageserver.Parameters) (*imageserver.Image, error) {
	item, err := cache.Memcache.Get(key)
	if err != nil {
		return nil, imageserver.NewCacheMissError(key, cache, err)
	}

	image, err := imageserver.NewImageUnmarshalBinary(item.Value)
	if err != nil {
		return nil, err
	}

	return image, nil
}

// Set sets an Image to Memcache
func (cache *MemcacheCache) Set(key string, image *imageserver.Image, parameters imageserver.Parameters) error {
	data, _ := image.MarshalBinary()

	item := &memcache_impl.Item{
		Key:   key,
		Value: data,
	}
	err := cache.Memcache.Set(item)

	return err
}
<commit_msg>small changes in MemcacheCache (for tests)<commit_after>// Package memcache provides a Memcache Image Cache
package memcache

import (
	memcache_impl "github.com/bradfitz/gomemcache/memcache"
	"github.com/pierrre/imageserver"
)

// MemcacheCache represents a Memcache Image Cache
//
// It uses <NAME>'s Memcache client https://github.com/bradfitz/gomemcache
type MemcacheCache struct {
	Client *memcache_impl.Client
}

// Get gets an Image from Memcache
func (cache *MemcacheCache) Get(key string, parameters imageserver.Parameters) (*imageserver.Image, error) {
	data, err := cache.getData(key)
	if err != nil {
		return nil, err
	}

	image, err := imageserver.NewImageUnmarshalBinary(data)
	if err != nil {
		return nil, err
	}

	return image, nil
}

func (cache *MemcacheCache) getData(key string) ([]byte, error) {
	item, err := cache.Client.Get(key)
	if err != nil {
		return nil, imageserver.NewCacheMissError(key, cache, err)
	}

	return item.Value, nil
}

// Set sets an Image to Memcache
func (cache *MemcacheCache) Set(key string, image *imageserver.Image, parameters imageserver.Parameters) error {
	data, _ := image.MarshalBinary()

	err := cache.setData(key, data)
	if err != nil {
		return err
	}

	return nil
}

func (cache *MemcacheCache) setData(key string, data []byte) error {
	err := cache.Client.Set(&memcache_impl.Item{
		Key:   key,
		Value: data,
	})
	if err != nil {
		return err
	}

	return nil
}

{'fraction_non_alphanumeric': 0.11467522052927025, 'fraction_numerical': 0.0, 'mean_word_length': 4.319829424307036, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '2729468', 'n_tokens_mistral': 859, 'n_tokens_neox': 821, 'n_words': 239}