Skip to content

Commit 1682657

Browse files
committed
Update README.md
1 parent d243517 commit 1682657

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,29 @@ class MyCustomCache(CacheInterface):
187187
handler = ipinfo.getHandler(cache=MyCustomCache())
188188
```
189189

190+
#### Accessing the cache directly
191+
192+
You can access/update the cache directly via a dictionary-like notation with a cache_key and the handler.
193+
194+
```python
195+
>>> import ipinfo
196+
>>> from ipinfo.handler_utils import cache_key
197+
>>> access_token = '123456789abc'
198+
>>> handler = ipinfo.getHandler(access_token)
199+
>>> ip_cache_key = cache_key('1.1.1.1')
200+
201+
# Check if the ip address is in the cache
202+
>>> ip_cache_key in handler.cache
203+
True
204+
205+
# Get the ip address's details from cache
206+
>>> handler.cache[ip_cache_key]
207+
{'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'}
208+
209+
# Remove the ip address from the cache
210+
>>> handler.cache[ip_cache_key] = None
211+
```
212+
190213
### Modifying request options
191214

192215
**Note**: the asynchronous handler currently only accepts the `timeout` option,

0 commit comments

Comments
 (0)