Skip to content

Commit

Permalink
Merge pull request #55 from mtzfederico/master
Browse files Browse the repository at this point in the history
Added info about accessing the cache directly
  • Loading branch information
UmanShahzad authored Jul 9, 2021
2 parents d243517 + 1682657 commit 95fc85f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 95fc85f

Please # to comment.