diff --git a/README.md b/README.md index 6e71f5f..2e49b62 100644 --- a/README.md +++ b/README.md @@ -187,6 +187,29 @@ class MyCustomCache(CacheInterface): handler = ipinfo.getHandler(cache=MyCustomCache()) ``` +#### Accessing the cache directly + +You can access/update the cache directly via a dictionary-like notation with a cache_key and the handler. + +```python +>>> import ipinfo +>>> from ipinfo.handler_utils import cache_key +>>> access_token = '123456789abc' +>>> handler = ipinfo.getHandler(access_token) +>>> ip_cache_key = cache_key('1.1.1.1') + +# Check if the ip address is in the cache +>>> ip_cache_key in handler.cache +True + +# Get the ip address's details from cache +>>> handler.cache[ip_cache_key] +{'ip': '1.1.1.1', 'hostname': 'one.one.one.one', 'anycast': True, 'city': 'Miami', 'region': 'Florida', 'country': 'US', 'loc': '25.7867,-80.1800', 'org': 'AS13335 Cloudflare, Inc.', 'postal': '33132', 'timezone': 'America/New_York', 'country_name': 'United States', 'latitude': '25.7867', 'longitude': '-80.1800'} + +# Remove the ip address from the cache +>>> handler.cache[ip_cache_key] = None +``` + ### Modifying request options **Note**: the asynchronous handler currently only accepts the `timeout` option,