Skip to content
This repository was archived by the owner on Feb 3, 2024. It is now read-only.

Commit eceae65

Browse files
author
DannyCork
authored
Merge pull request #256 from sorrowless/feat/cache-age
Add an opportunity to specify max cache age
2 parents d7dd9f1 + 9f8779c commit eceae65

File tree

5 files changed

+11
-4
lines changed

5 files changed

+11
-4
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ Raise an issue https://github.com/DannyCork/python-whois/issues/new
7373
* add support for returning the raw data from the whois command: flag include_raw_whois_text
7474
* add support for handling unsupported domains via whois raw text only: flag return_raw_text_for_unsupported_tld
7575

76+
2023-01-18: sorrowless
77+
* add an opportunity to specify maximum cache age
78+
7679
## Support
7780
* Python 3.x is supported.
7881
* Python 2.x IS NOT supported.

makeTestdataAll.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /bin/bash
1+
#! /usr/bin/env bash
22

33
TMPDIR="./tmp" # the default work directory is a local tmp (exclude by .gitignore )
44

test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /usr/bin/bash
1+
#! /usr/bin/env bash
22

33
# signal whois module that we are testing, this reads data from testdata/<domain>/in
44
prepPath()
@@ -22,7 +22,7 @@ testOneDomain()
2222
echo "testing: $domain"
2323
./test2.py -d "$domain" >"$TestDataDir/$domain/test.out"
2424

25-
diff "$TestDataDir/$domain/output" "$TestDataDir/$domain/test.out" |
25+
diff "$TestDataDir/$domain/output" "$TestDataDir/$domain/test.out" |
2626
tee "$TestDataDir/$domain/diff.out"
2727
}
2828

whois/_1_query.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def do_query(
4141
dl: List[str],
4242
force: bool = False,
4343
cache_file: Optional[str] = None,
44+
cache_age: int = CACHE_MAX_AGE,
4445
slow_down: int = 0,
4546
ignore_returncode: bool = False,
4647
server: Optional[str] = None,
@@ -53,7 +54,7 @@ def do_query(
5354

5455
# actually also whois uses cache, so if you really dont want to use cache
5556
# you should also pass the --force-lookup flag (on linux)
56-
if force or k not in CACHE or CACHE[k][0] < time.time() - CACHE_MAX_AGE:
57+
if force or k not in CACHE or CACHE[k][0] < time.time() - cache_age:
5758
# slow down before so we can force individual domains at a slower tempo
5859
if slow_down:
5960
time.sleep(slow_down)

whois/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ def query(
305305
domain: str,
306306
force: bool = False,
307307
cache_file: Optional[str] = None,
308+
cache_age: int = 60 * 60 * 48,
308309
slow_down: int = 0,
309310
ignore_returncode: bool = False,
310311
server: Optional[str] = None,
@@ -317,6 +318,7 @@ def query(
317318
"""
318319
force=True Don't use cache.
319320
cache_file=<path> Use file to store cache not only memory.
321+
cache_age=172800 Cache expiration time for given domain, in seconds
320322
slow_down=0 Time [s] it will wait after you query WHOIS database.
321323
This is useful when there is a limit to the number of requests at a time.
322324
server: if set use the whois server explicitly for making the query:
@@ -368,6 +370,7 @@ def query(
368370
dl=dl,
369371
force=force,
370372
cache_file=cache_file,
373+
cache_age=cache_age,
371374
slow_down=slow_down,
372375
ignore_returncode=ignore_returncode,
373376
server=server,

0 commit comments

Comments
 (0)