<commit_before>//
//  Caching.swift
//  AsyncImageView
//
//  Created by <NAME> on 9/17/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation

public protocol CacheType {
	typealias Key: Hashable
	typealias Value

	/// Retrieves the value for this key.
	func valueForKey(key: Key) -> Value?

	/// Sets a value for a key. If `value` is `nil`, it will be removed.
	func setValue(value: Value?, forKey key: Key)
}

/// `CacheType` backed by `NSCache`.
public final class InMemoryCache<K: Hashable, V>: CacheType {
	private let cache: NSCache

	public init(cacheName: String) {
		self.cache = {
			let cache = NSCache()
			cache.name = cacheName

			return cache
		}()
	}

	public func valueForKey(key: K) -> V? {
		return (cache.objectForKey(CacheKey(value: key)) as! CacheValue<V>?)?.value
	}

	public func setValue(value: V?, forKey key: K) {
		let key = CacheKey(value: key)<commit_msg>Caching: dropped Hashable requirement. Only required by InMemoryCache<commit_after>//
//  Caching.swift
//  AsyncImageView
//
//  Created by <NAME> on 9/17/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation

public protocol CacheType {
	typealias Key
	typealias Value

	/// Retrieves the value for this key.
	func valueForKey(key: Key) -> Value?

	/// Sets a value for a key. If `value` is `nil`, it will be removed.
	func setValue(value: Value?, forKey key: Key)
}

/// `CacheType` backed by `NSCache`.
public final class InMemoryCache<K: Hashable, V>: CacheType {
	private let cache: NSCache

	public init(cacheName: String) {
		self.cache = {
			let cache = NSCache()
			cache.name = cacheName

			return cache
		}()
	}

	public func valueForKey(key: K) -> V? {
		return (cache.objectForKey(CacheKey(value: key)) as! CacheValue<V>?)?.value
	}

	public func setValue(value: V?, forKey key: K) {
		let key = CacheKey(value: key)
{'fraction_non_alphanumeric': 0.13050483351235231, 'fraction_numerical': 0.00966702470461869, 'mean_word_length': 3.414691943127962, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '1048445', 'n_tokens_mistral': 675, 'n_tokens_neox': 625, 'n_words': 209}