示例#1
0
        public void Add <TRecord>(DomainName name, RecordType recordType, RecordClass recordClass, IEnumerable <TRecord> records, DnsSecValidationResult validationResult, int timeToLive)
            where TRecord : DnsRecordBase
        {
            DnsCacheRecordList <DnsRecordBase> cacheValues = new DnsCacheRecordList <DnsRecordBase>();

            cacheValues.AddRange(records);
            cacheValues.ValidationResult = validationResult;

            Add(name, recordType, recordClass, cacheValues, timeToLive);
        }
示例#2
0
        public bool TryGetRecords <TRecord>(DomainName name, RecordType recordType, RecordClass recordClass, out DnsCacheRecordList <TRecord> records)
            where TRecord : DnsRecordBase
        {
            CacheKey key    = new CacheKey(name, recordType, recordClass);
            DateTime utcNow = DateTime.UtcNow;

            CacheValue cacheValue;

            if (_cache.TryGetValue(key, out cacheValue))
            {
                if (cacheValue.ExpireDateUtc < utcNow)
                {
                    _cache.TryRemove(key, out cacheValue);
                    records = null;
                    return(false);
                }

                int ttl = (int)(cacheValue.ExpireDateUtc - utcNow).TotalSeconds;

                records = new DnsCacheRecordList <TRecord>();

                records.AddRange(cacheValue
                                 .Records
                                 .OfType <TRecord>()
                                 .Select(x =>
                {
                    TRecord record    = x.Clone <TRecord>();
                    record.TimeToLive = ttl;
                    return(record);
                }));

                records.ReturnCode       = cacheValue.Records.ReturnCode;
                records.ValidationResult = cacheValue.Records.ValidationResult;

                return(true);
            }

            records = null;
            return(false);
        }
示例#3
0
 public CacheValue(DnsCacheRecordList <DnsRecordBase> records, int timeToLive)
 {
     Records       = records;
     ExpireDateUtc = DateTime.UtcNow.AddSeconds(timeToLive);
 }
示例#4
0
        public void Add(DomainName name, RecordType recordType, RecordClass recordClass, DnsCacheRecordList <DnsRecordBase> records, int timeToLive)
        {
            CacheKey key = new CacheKey(name, recordType, recordClass);

            _cache.TryAdd(key, new CacheValue(records, timeToLive));
        }