<commit_before># Cacher

[![TravisCI](https://travis-ci.org/jelmersnoeck/cacher.svg)](https://travis-ci.org/jelmersnoeck/cacher) [![GoDoc reference](https://camo.githubusercontent.com/fb9e66520f8775e97dcacdf366d0dee7828df53f/68747470733a2f2f676f646f632e6f72672f6769746875622e636f6d2f676f2d6d617274696e692f6d617274696e693f7374617475732e706e67)](https://godoc.org/github.com/jelmersnoeck/cacher)

Cacher is a port of the PHP library [Scrapbook](https://github.com/matthiasmullie/scrapbook).

It defines an interface to interact with several cache systems without having to
worry about the implementation of said cache layer.

## Methods

#### `Add(key string, value interface{}, ttl int) bool`

Adds a new key to the cache if the key is not already stored. If the key is
already stored false will be returned.

#### `Set(key string, value interface{}, ttl int) bool`

Sets the value for the specified key, regardless of wether or not the key has
already been set. If the key has already been set, it will overwrite the
previous value.

#### `SetMulti(items map[string]interface{}, ttl int) map[string]bool`

A shorthand to set multiple key/value combinations at a time. This uses `Set`
internally to add the items to the cache.

#### `Increment(key string, initial, offset, ttl int) bool`

Increments the initial value - or cached value if present - by offset.

#### `Decrement(key string, initial, offset, ttl int) bool`

Decrements the initial value - or cached value if present - by offset.

#### `Replace(key string, value interface{}, ttl int) bool`

Replace will update a value, only if it is present. If it is not present, false
will be returned.

#### `Get(key string) interface{}`

Gets the value for the given key.

#### `GetMulti(keys []string) map[string]interface{}`

Gets a list of values for a range of given keys. This uses `Get` internally.

#### `Flush() bool`

Resets the cache store and deletes all cached values.

#### `Delete(key string) bool`

Deletes a key from the cache.

#### `DeleteMulti(keys []string) map[string]bool`

Deletes multiple keys at a time and returns with a result set to see if the
deletes were successful.

## Implementations

### MemoryCache

MemoryCache stores all the data in memory. This is a non persistent cache store
that will be flushed every time the application that uses the cache is
terminates.

This cache is perfect to use for testing. There are no other dependencies
required other than enough available memory.<commit_msg>Readme: update interface{} to []byte.<commit_after># Cacher

[![TravisCI](https://travis-ci.org/jelmersnoeck/cacher.svg)](https://travis-ci.org/jelmersnoeck/cacher) [![GoDoc reference](https://camo.githubusercontent.com/fb9e66520f8775e97dcacdf366d0dee7828df53f/68747470733a2f2f676f646f632e6f72672f6769746875622e636f6d2f676f2d6d617274696e692f6d617274696e693f7374617475732e706e67)](https://godoc.org/github.com/jelmersnoeck/cacher)

Cacher is a port of the PHP library [Scrapbook](https://github.com/matthiasmullie/scrapbook).

It defines an interface to interact with several cache systems without having to
worry about the implementation of said cache layer.

## Methods

#### `Add(key string, value []byte, ttl int) bool`

Adds a new key to the cache if the key is not already stored. If the key is
already stored false will be returned.

#### `Set(key string, value []byte, ttl int) bool`

Sets the value for the specified key, regardless of wether or not the key has
already been set. If the key has already been set, it will overwrite the
previous value.

#### `SetMulti(items map[string][]byte, ttl int) map[string]bool`

A shorthand to set multiple key/value combinations at a time. This uses `Set`
internally to add the items to the cache.

#### `Increment(key string, initial, offset, ttl int) bool`

Increments the initial value - or cached value if present - by offset.

#### `Decrement(key string, initial, offset, ttl int) bool`

Decrements the initial value - or cached value if present - by offset.

#### `Replace(key string, value []byte, ttl int) bool`

Replace will update a value, only if it is present. If it is not present, false
will be returned.

#### `Get(key string) []byte`

Gets the value for the given key.

#### `GetMulti(keys []string) map[string][]byte`

Gets a list of values for a range of given keys. This uses `Get` internally.

#### `Flush() bool`

Resets the cache store and deletes all cached values.

#### `Delete(key string) bool`

Deletes a key from the cache.

#### `DeleteMulti(keys []string) map[string]bool`

Deletes multiple keys at a time and returns with a result set to see if the
deletes were successful.

## Implementations

### MemoryCache

MemoryCache stores all the data in memory. This is a non persistent cache store
that will be flushed every time the application that uses the cache is
terminates.

This cache is perfect to use for testing. There are no other dependencies
required other than enough available memory.
{'fraction_non_alphanumeric': 0.09366168752523213, 'fraction_numerical': 0.046830843762616065, 'mean_word_length': 4.898809523809524, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 10, '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': '1284154', 'n_tokens_mistral': 1656, 'n_tokens_neox': 1505, 'n_words': 627}