<commit_before><?php

class dmAPCCache extends sfAPCCache
{
  protected static
    $isApcEnabled;

  public function __construct($options = array())
  {
    if (isset($options['cache_dir']))
    {
      $name = substr($options['cache_dir'], strlen(sfConfig::get('sf_cache_dir'))+1);
    }
    elseif(isset($options['prefix']))
    {
      $name = dmProject::unRootify($options['prefix']);
    }
    else
    {
      throw new dmException('You must provide a cache_dir or a prefix');
    }
    
    $this->initialize(array(
      'prefix' => dmProject::getKey().'/'.$name,
    ));
  }

  public function set($key, $data, $lifetime = null)
  {
    return parent::set($key, serialize($data), $lifetime);
  }

  public function _set($key, $data, $lifetime = null)
  {
    return parent::set($key, $data, $lifetime);
  }

  public function get($key, $default = null)
  {
    $data = parent::get($key, $default);

    if ($data != $default)
    {
      $data = unserialize($data);
    }

    return $data;
  }

  /*
   * will not unserialize result<commit_msg>[Diem] made APC cache driver more robust<commit_after><?php

class dmAPCCache extends sfAPCCache
{
  protected static
    $isApcEnabled;

  public function __construct($options = array())
  {
    if (isset($options['cache_dir']))
    {
      $name = substr($options['cache_dir'], strlen(sfConfig::get('sf_cache_dir'))+1);
    }
    elseif(isset($options['prefix']))
    {
      $name = dmProject::unRootify($options['prefix']);
    }
    else
    {
      throw new dmException('You must provide a cache_dir or a prefix');
    }
    
    $this->initialize(array(
      'prefix' => sfConfig::get('sf_root_dir').'/'.$name,
    ));
  }

  public function set($key, $data, $lifetime = null)
  {
    return parent::set($key, serialize($data), $lifetime);
  }

  public function _set($key, $data, $lifetime = null)
  {
    return parent::set($key, $data, $lifetime);
  }

  public function get($key, $default = null)
  {
    $data = parent::get($key, $default);

    if ($data != $default)
    {
      $data = unserialize($data);
    }

    return $data;
  }

  /*
   * will not unserialize result
{'fraction_non_alphanumeric': 0.16884328358208955, 'fraction_numerical': 0.0009328358208955224, 'mean_word_length': 3.1170825335892514, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '1556484', 'n_tokens_mistral': 726, 'n_tokens_neox': 707, 'n_words': 151}