<commit_before>import { createSelector } from 'reselect';
import FlatCacheObject from './cache/FlatCacheObject';

export default function createCachedSelector(...funcs) {
  const defaultCacheCreator = FlatCacheObject;

  return (resolver, options = {}) => {
    let cache;
    let selectorCreator;

    // Allow "options" to be provided as a "selectorCreator" for backward compatibility
    // @TODO Remove "options" as a function in next breaking release
    if(typeof options === 'function') {
      cache = new defaultCacheCreator();
      selectorCreator = options;
    } else {
      cache = options.cacheObject || new defaultCacheCreator();
      selectorCreator = options.selectorCreator || createSelector;
    }

    const selector = function(...args) {
      // Application receives this function
      const cacheKey = resolver(...args);

      if (typeof cacheKey === 'string' || typeof cacheKey === 'number') {
        let cacheResult = cache.get(cacheKey);

        if (cacheResult === undefined) {
          cache.set(cacheKey, selectorCreator(...funcs));
          cacheResult = cache.get(cacheKey);
        }

        return cacheResult(...args);
      }
      return undefined;
    };

    // Further selector methods
    selector.getMatchingSelector = (...args) => {
      const cacheKey = resolver(...args);
      // @NOTE It might update cache hit count in LRU-like caches
      return cache.get(cacheKey);
    };

    selector.removeMatchingSelector = (...args) => {
      const cacheKey = resolver(...args);
      cache.remove(cacheKey);
    };

    selector.clearCache = () => {
      cache.clear();
    };

    selector.resultFunc = funcs[funcs.length -1];

    return selector;
  }
}<commit_msg>Expose optional cache object as named exports<commit_after>import { createSelector } from 'reselect';
import FlatCacheObject from './cache/FlatCacheObject';

export default function createCachedSelector(...funcs) {
  const defaultCacheCreator = FlatCacheObject;

  return (resolver, options = {}) => {
    let cache;
    let selectorCreator;

    // Allow "options" to be provided as a "selectorCreator" for backward compatibility
    // @TODO Remove "options" as a function in next breaking release
    if(typeof options === 'function') {
      cache = new defaultCacheCreator();
      selectorCreator = options;
    } else {
      cache = options.cacheObject || new defaultCacheCreator();
      selectorCreator = options.selectorCreator || createSelector;
    }

    const selector = function(...args) {
      // Application receives this function
      const cacheKey = resolver(...args);

      if (typeof cacheKey === 'string' || typeof cacheKey === 'number') {
        let cacheResult = cache.get(cacheKey);

        if (cacheResult === undefined) {
          cache.set(cacheKey, selectorCreator(...funcs));
          cacheResult = cache.get(cacheKey);
        }

        return cacheResult(...args);
      }
      return undefined;
    };

    // Further selector methods
    selector.getMatchingSelector = (...args) => {
      const cacheKey = resolver(...args);
      // @NOTE It might update cache hit count in LRU-like caches
      return cache.get(cacheKey);
    };

    selector.removeMatchingSelector = (...args) => {
      const cacheKey = resolver(...args);
      cache.remove(cacheKey);
    };

    selector.clearCache = () => {
      cache.clear();
    };

    selector.resultFunc = funcs[funcs.length -1];

    return selector;
  }
}

export { FlatCacheObject };
export { default as FifoCacheObject } from './cache/FifoCacheObject';
export { default as LruCacheObject } from './cache/LruCacheObject';
{'fraction_non_alphanumeric': 0.12393514701841166, 'fraction_numerical': 0.0005496015388843089, 'mean_word_length': 2.775933609958506, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '1143242', 'n_tokens_mistral': 1008, 'n_tokens_neox': 976, 'n_words': 266}