<commit_before>(function (global) {
  var Stash = global.Stash || {};
  var isNode = typeof require !== 'undefined';
  var Promise = global.Promise;

  if (isNode) {
    Promise = require('bluebird');
  }

  Stash.Item = (function () {
    function Item(key, pool) {
      this.key = key;
      this.pool = pool;

      this._unload_();
    }

    Item.SP_NONE = 1;
    Item.SP_OLD = 2;
    Item.SP_PRECOMPUTE = 4;
    Item.SP_VALUE = 8;

    Item.prototype._unload_ = function () {
      this.value = null;
      this.expiration = false;
      this.locked = undefined;
    };

    Item.prototype._load_ = function (callback) {
      var that = this;

      return new Promise(function (resolve, reject) {
        that.pool.drivers.forEach(function (d) {
          d.get(that.key).then(resolve);
        });
      });
    };

    Item.prototype._write_ = function (callback) {
      var that = this;

      return new Promise(function (resolve, reject) {
        that.pool.drivers.reverse().forEach(function (d) {
          d.put(that.key, that.value, that.expiration).then(resolve);
        });
      });
    };

    Item._calculateExpiration_ = function (expiration) {
      if (typeof(expiration) === 'number') {
        expiration *= 1000;
        expiration += Date.now();
      } else if (expiration instanceof Date) {
        expiration = expiration.getTime();
      }

      return expiration;
    };

    Item.prototype.get = function (cachePolicy, policyData) {
      var that = this;
      this.cachePolicy = cachePolicy || Stash.Item.SP_NONE;
      this.policyData = policyData;

      function load(resolve) {
        that._load_().then(function (data) {
          if (data) {
            that.value = data.value;
            that.expiration = data.expiration;
            data = data.value || null;
          }

          resolve(data);
        });
      }

      return new Promise(function (resolve, reject) {
        if (that.cachePolicy & Stash.Item.SP_VALUE) {
          that.isLocked().then(function (locked) {
            if (locked) {
              resolve(that.policyData);
            } else {
              load(resolve);
            }
          });
        } else {
          load(resolve);
        }
      });
    };

    Item.prototype.set = function (value, expiration, callback) {
      if (typeof expiration === 'function') {
        callback = expiration;
        expiration = null;
      }

      this._unload_();

      this.expiration = Item._calculateExpiration_(expiration);
      this.value = value;

      this.unlock();
      return this._write_();
    };

    Item.prototype.isMiss = function (callback) {
      var that = this;

      var isMissed = function (locked, resolve) {
        var miss;

        if (locked && (that.cachePolicy & Stash.Item.SP_OLD)) {
          miss = false;
        } else if (!locked &&
                   (that.cachePolicy & Stash.Item.SP_PRECOMPUTE) &&
                   that.policyData * 1000 >= that.expiration - Date.now()) {
          miss =  true;
        } else {
          miss = that.value === null ||
            typeof(that.expiration) === 'number' &&<commit_msg>add alias for set - syntax sugar for cache saving on pool#get error<commit_after>(function (global) {
  var Stash = global.Stash || {};
  var isNode = typeof require !== 'undefined';
  var Promise = global.Promise;

  if (isNode) {
    Promise = require('bluebird');
  }

  Stash.Item = (function () {
    function Item(key, pool) {
      this.key = key;
      this.pool = pool;

      this._unload_();
    }

    Item.SP_NONE = 1;
    Item.SP_OLD = 2;
    Item.SP_PRECOMPUTE = 4;
    Item.SP_VALUE = 8;

    Item.prototype._unload_ = function () {
      this.value = null;
      this.expiration = false;
      this.locked = undefined;
    };

    Item.prototype._load_ = function (callback) {
      var that = this;

      return new Promise(function (resolve, reject) {
        that.pool.drivers.forEach(function (d) {
          d.get(that.key).then(resolve);
        });
      });
    };

    Item.prototype._write_ = function (callback) {
      var that = this;

      return new Promise(function (resolve, reject) {
        that.pool.drivers.reverse().forEach(function (d) {
          d.put(that.key, that.value, that.expiration).then(resolve);
        });
      });
    };

    Item._calculateExpiration_ = function (expiration) {
      if (typeof(expiration) === 'number') {
        expiration *= 1000;
        expiration += Date.now();
      } else if (expiration instanceof Date) {
        expiration = expiration.getTime();
      }

      return expiration;
    };

    Item.prototype.get = function (cachePolicy, policyData) {
      var that = this;
      this.cachePolicy = cachePolicy || Stash.Item.SP_NONE;
      this.policyData = policyData;

      function load(resolve) {
        that._load_().then(function (data) {
          if (data) {
            that.value = data.value;
            that.expiration = data.expiration;
            data = data.value || null;
          }

          resolve(data);
        });
      }

      return new Promise(function (resolve, reject) {
        if (that.cachePolicy & Stash.Item.SP_VALUE) {
          that.isLocked().then(function (locked) {
            if (locked) {
              resolve(that.policyData);
            } else {
              load(resolve);
            }
          });
        } else {
          load(resolve);
        }
      });
    };

    Item.prototype.save = // alias for better syntax on Pool#get
    Item.prototype.set = function (value, expiration, callback) {
      if (typeof expiration === 'function') {
        callback = expiration;
        expiration = null;
      }

      this._unload_();

      this.expiration = Item._calculateExpiration_(expiration);
      this.value = value;

      this.unlock();
      return this._write_();
    };

    Item.prototype.isMiss = function (callback) {
      var that = this;

      var isMissed = function (locked, resolve) {
        var miss;

        if (locked && (that.cachePolicy & Stash.Item.SP_OLD)) {
          miss = false;
        } else if (!locked &&
                   (that.cachePolicy & Stash.Item.SP_PRECOMPUTE) &&
                   that.policyData * 1000 >= that.expiration - Date.now()) {
          miss =  true;
        } else {
          miss = that.value === null ||
            typeof(that.expiration) === 'number' &&
{'fraction_non_alphanumeric': 0.13129580539529082, 'fraction_numerical': 0.0037423982535474817, 'mean_word_length': 1.8749439713133125, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1399550', 'n_tokens_mistral': 1930, 'n_tokens_neox': 1849, 'n_words': 402}