<commit_before>'use strict';

var _ = require('../underscore');
var DisabledCache = require('./DisabledCache');
var utils = require('../utils');
var CacheManager = require('./CacheManager');

var MemoryStore = require('./MemoryStore');
var MemcachedStore = require('./MemcachedStore');
var RedisStore = require('./RedisStore');

var CACHE_REGIONS = ['applications', 'directories', 'accounts', 'groups',
  'groupMemberships', 'tenants', 'accountStoreMappings'];

// private function
function getCacheCtor(cache){
  if (!cache){
    return;
  }

  if (typeof cache === 'function'){
    return cache;
  }

  var cacheCtors = {
    memory: MemoryStore,
    memcached: MemcachedStore,
    redis: RedisStore
  };

  if (!(cache in cacheCtors)){
    throw new Error('Unsupported cache provider: ' + cache);
  }

  return cacheCtors[cache];
}

// * Example of a object with all available options::
//{
//  store: 'redis',
//  connection: {
//    host: 'localhost',
//    port: 6739,
//  },
//  options: {},
//  ttl: 300,
//  tti: 300
//}

function CacheHandler(config) {
  var self = this;
  config = config || {};
  var options = config.cacheOptions || {};
  options.store = getCacheCtor(options.store);
<commit_msg>added runtime loading of store providers<commit_after>'use strict';

var _ = require('../underscore');
var DisabledCache = require('./DisabledCache');
var utils = require('../utils');
var CacheManager = require('./CacheManager');

var CACHE_REGIONS = ['applications', 'directories', 'accounts', 'groups',
  'groupMemberships', 'tenants', 'accountStoreMappings'];

// private function
function getCacheCtor(cache){
  if (!cache){
    return;
  }

  if (typeof cache === 'function'){
    return cache;
  }

  function runtimeLoad(moduleRef){
    return require(moduleRef);
  }

  var cacheCtors = {
    memory: runtimeLoad('./MemoryStore'),
    memcached: runtimeLoad('./MemcachedStore'),
    redis: runtimeLoad('./RedisStore')
  };

  if (!(cache in cacheCtors)){
    throw new Error('Unsupported cache provider: ' + cache);
  }

  return cacheCtors[cache]();
}

// * Example of a object with all available options::
//{
//  store: 'redis',
//  connection: {
//    host: 'localhost',
//    port: 6739,
//  },
//  options: {},
//  ttl: 300,
//  tti: 300
//}

function CacheHandler(config) {
  var self = this;
  config = config || {};
  var options = config.cacheOptions || {};
  options.store = getCacheCtor(options.store);

{'fraction_non_alphanumeric': 0.17228618421052633, 'fraction_numerical': 0.008223684210526315, 'mean_word_length': 3.669865642994242, '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': '4118737', 'n_tokens_mistral': 785, 'n_tokens_neox': 749, 'n_words': 192}