// Generated by CoffeeScript 1.12.1
(function() {
  var CACHE, Cache, _;

  _ = {
    pull: require('lodash/pull'),
    isEmpty: require('lodash/isEmpty')
  };

  CACHE = {};

  Cache = (function() {
    function Cache() {}

    Cache.clearAll = function() {
      return CACHE = {};
    };

    Cache.get = function(type, hostname) {
      var ref;
      return (ref = CACHE[type]) != null ? ref[hostname] : void 0;
    };

    Cache.has = function(type, hostname) {
      var ref;
      return ((ref = CACHE[type]) != null ? ref[hostname] : void 0) != null;
    };

    Cache.pull = function(type, hostname, address) {
      var ref, ref1, ref2;
      _.pull((ref = CACHE[type]) != null ? ref[hostname] : void 0, address);
      if (_.isEmpty((ref1 = CACHE[type]) != null ? ref1[hostname] : void 0)) {
        return (ref2 = CACHE[type]) != null ? delete ref2[hostname] : void 0;
      }
    };

    Cache.set = function(type, hostname, address, ttl) {
      var base, delay, deleteAddress;
      if (CACHE[type] == null) {
        CACHE[type] = {};
      }
      if ((base = CACHE[type])[hostname] == null) {
        base[hostname] = [];
      }
      CACHE[type][hostname].push(address);
      deleteAddress = function() {
        return Cache.pull('SRV', hostname, address);
      };
      delay = 1000 * ttl;
      return setTimeout(deleteAddress, delay);
    };

    return Cache;

  })();

  module.exports = Cache;

}).call(this);
