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

Commit

Permalink
Merge pull request #256 from sorrowless/feat/cache-age
Browse files Browse the repository at this point in the history
Add an opportunity to specify max cache age
  • Loading branch information
DannyCork authored Jan 24, 2023
2 parents d7dd9f1 + 9f8779c commit eceae65
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ Raise an issue https://github.com/DannyCork/python-whois/issues/new
* add support for returning the raw data from the whois command: flag include_raw_whois_text
* add support for handling unsupported domains via whois raw text only: flag return_raw_text_for_unsupported_tld

2023-01-18: sorrowless
* add an opportunity to specify maximum cache age

## Support
* Python 3.x is supported.
* Python 2.x IS NOT supported.
2 changes: 1 addition & 1 deletion makeTestdataAll.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /bin/bash
#! /usr/bin/env bash

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

Expand Down
4 changes: 2 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/bash
#! /usr/bin/env bash

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

diff "$TestDataDir/$domain/output" "$TestDataDir/$domain/test.out" |
diff "$TestDataDir/$domain/output" "$TestDataDir/$domain/test.out" |
tee "$TestDataDir/$domain/diff.out"
}

Expand Down
3 changes: 2 additions & 1 deletion whois/_1_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def do_query(
dl: List[str],
force: bool = False,
cache_file: Optional[str] = None,
cache_age: int = CACHE_MAX_AGE,
slow_down: int = 0,
ignore_returncode: bool = False,
server: Optional[str] = None,
Expand All @@ -53,7 +54,7 @@ def do_query(

# actually also whois uses cache, so if you really dont want to use cache
# you should also pass the --force-lookup flag (on linux)
if force or k not in CACHE or CACHE[k][0] < time.time() - CACHE_MAX_AGE:
if force or k not in CACHE or CACHE[k][0] < time.time() - cache_age:
# slow down before so we can force individual domains at a slower tempo
if slow_down:
time.sleep(slow_down)
Expand Down
3 changes: 3 additions & 0 deletions whois/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ def query(
domain: str,
force: bool = False,
cache_file: Optional[str] = None,
cache_age: int = 60 * 60 * 48,
slow_down: int = 0,
ignore_returncode: bool = False,
server: Optional[str] = None,
Expand All @@ -317,6 +318,7 @@ def query(
"""
force=True Don't use cache.
cache_file=<path> Use file to store cache not only memory.
cache_age=172800 Cache expiration time for given domain, in seconds
slow_down=0 Time [s] it will wait after you query WHOIS database.
This is useful when there is a limit to the number of requests at a time.
server: if set use the whois server explicitly for making the query:
Expand Down Expand Up @@ -368,6 +370,7 @@ def query(
dl=dl,
force=force,
cache_file=cache_file,
cache_age=cache_age,
slow_down=slow_down,
ignore_returncode=ignore_returncode,
server=server,
Expand Down

0 comments on commit eceae65

Please sign in to comment.