dns :: resolver :: LRUCache :: Class LRUCache |
[hide private]
[frames] | no frames]

# Class LRUCache

source code

    object --+
             |
            LRUCache

Bounded least-recently-used DNS answer cache.

This cache is better than the simple cache (above) if you're running a web crawler or other process that does a lot of resolutions. The LRUCache has a maximum number of nodes, and when it is full, the least-recently used node is removed to make space for a new one.

Instance Methods | [hide private]
__init__(self, max_size=100000) Initialize a DNS cache. | source code
set_max_size(self, max_size) | source code
dns.resolver.Answer object or None |
get(self, key) Get the answer associated with key. | source code
put(self, key, value) Associate key and value in the cache. | source code
flush(self, key=None) Flush the cache. | source code
Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Instance Variables | [hide private]
dict | data A dictionary of cached data
int | max_size The maximum number of nodes
LRUCacheNode object | sentinel sentinel node for circular doubly linked list of nodes

Properties | [hide private]
Inherited from `object`: `__class__`

Method Details | [hide private]

### __init__(self, max_size=100000) (Constructor) | source code
Initialize a DNS cache. Parameters: `max_size` (int) - The maximum number of nodes to cache; the default is 100,000. Must be greater than 1. Overrides: object.__init__

### get(self, key) | source code
Get the answer associated with key. Returns None if no answer is cached for the key. Parameters: `key` ((dns.name.Name, int, int) tuple whose values are the query name, rdtype, and rdclass.) - the key Returns: dns.resolver.Answer object or None

### put(self, key, value) | source code
Associate key and value in the cache. Parameters: `key` ((dns.name.Name, int, int) tuple whose values are the query name, rdtype, and rdclass.) - the key `value` (dns.resolver.Answer object) - The answer being cached

### flush(self, key=None) | source code
Flush the cache. If key is specified, only that item is flushed. Otherwise the entire cache is flushed. Parameters: `key` ((dns.name.Name, int, int) tuple or None) - the key to flush