- Notifications
You must be signed in to change notification settings - Fork0
DNS lookup cache for Python using dnspython
License
jayvdb/dns-cache
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
dns-cache is a Python client side DNS caching framework utilisingdnspython v1.15+ for DNSand supports various local key stores, and provides caching of lookup failures,and configurable expiration of cached responses.
Some reasons to use a client side cache include:
- processing data containing many repeated invalid domains,
- running a local DNS caching service is not practical or appropriate,
- adding reporting of DNS activity performed within a job.
The recommended way to installdns-cache is by using pip as follows:
pip install dns-cache
To quickly benefit from client side dns-caching in your existing application, install the system resolver.
importdns_cacheimportrequestsdns_cache.override_system_resolver()foriinrange(10):requests.get('http://www.coala.io/')
If you have a fast dns proxy, 10 requests will possibly show no performance improvement.Even 100 may not perform better in this contrived example.
However when many parts of a system are performing lookups on the same DNS records, or wheresessions are being closed and new ones created and need to access the same DNS records,the difference becomes more noticable, especially in jobs which takes hours to run.
For long running jobs, use themin_ttl argument to increase the default if 5 minutes isnt sufficient.It can be set todns_cache.NO_EXPIRY for a ttl of one week, which is not recommended except whenaccompanied with custom cache expiration logic.
Multiple key stores are supported, and their dependencies need to added separately as required.
pickleandpickle4backport:dns_cache.pickle.PickableCachediskcache:dns_cache.diskcache.DiskCachestash.py:dns_cache.stash.StashCachesqlitedict:dns_cache.sqlitedict.SqliteDictCachedisk_dict:dns_cache.disk_dict.DiskDictCache(Python 2.7 only)
stash.py support usespickle orjsonpickle on Python 3, however onlyjsonpickle works on Python 2.7.
The following classes can be used separately or together.
dns_cache.resolver.AggressiveCachingResolver: indexes all qnames in the response, increasing the number of keys,but reducing the number of requests and cached responses when several related records are requested, such as a HTTP redirectfromwww.foo.com to foo.com (or vis versa) where one is a CNAME point to the other.dns_cache.resolver.ExceptionCachingResolver: caches lookup failures.dns_cache.hosts.HostsCache: preloads hosts (e.g./etc/hosts) into a cache
Note:dns_cache.override_system_resolver() can be used to install a customresolver orcache, which maybe derived from the above classes or your own implementation from scratch. It preloads/etc/hosts.
Python:
velocityis a lighter weight approach, with aserious bugdnsplug, unfortunately not available on PyPI.
Other:
dnscache(Go)native-dns-cache(Node)
About
DNS lookup cache for Python using dnspython
Topics
Resources
License
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.