LumiSoft.Net.Dns.Client.DnsCache.AddToCache C# (CSharp) Method

AddToCache() public static method

Adds dns records to cache. If old entry exists, it is replaced.
public static AddToCache ( string qname, int qtype, DnsServerResponse answers ) : void
qname string
qtype int
answers DnsServerResponse
return void
        public static void AddToCache(string qname,int qtype,DnsServerResponse answers)
        {
            if(answers == null){
                return;
            }

            try{
                lock(m_pCache){
                    // Remove old cache entry, if any.
                    if(m_pCache.Contains(qname + qtype)){
                        m_pCache.Remove(qname + qtype);
                    }
                    m_pCache.Add(qname + qtype,new DnsCacheEntry(answers,DateTime.Now));
                }
            }
            catch{
            }
        }

Usage Example

Example #1
0
        /// <summary>
        /// Is called when IPv6 socket has received data.
        /// </summary>
        /// <param name="ar">The result of the asynchronous operation.</param>
        private void IPv6ReceiveCompleted(IAsyncResult ar)
        {
            try{
                if (m_IsDisposed)
                {
                    return;
                }

                EndPoint remoteEP = new IPEndPoint(IPAddress.Any, 0);
                int      count    = m_pIPv6Socket.EndReceiveFrom(ar, ref remoteEP);

                DnsServerResponse serverResponse = ParseQuery((byte[])ar.AsyncState);
                DnsTransaction    transaction    = null;
                // Pass response to transaction.
                if (m_pTransactions.TryGetValue(serverResponse.ID, out transaction))
                {
                    transaction.ProcessResponse(serverResponse);
                }
                // No such transaction or transaction has timed out before answer received.
                //else{
                //}

                // Cache query.
                if (m_UseDnsCache && serverResponse.ResponseCode == RCODE.NO_ERROR)
                {
                    DnsCache.AddToCache(transaction.QName, transaction.QType, serverResponse);
                }
            }
            catch {
                // Skip receiving socket errors.
            }

            try{
                StartWaitingIPv6Packet();
            }
            catch {
            }
        }
All Usage Examples Of LumiSoft.Net.Dns.Client.DnsCache::AddToCache