Skip to content

Commit 1b8aad4

Browse files
Disable caching by default
1 parent 5aa5067 commit 1b8aad4

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
## [1.1.0] - 2020-07-05
10+
## [2.0.0] - 2020-07-05
1111
### Changed
12+
- Disable caching by default since people are often confused by this default setting. You can enable caching by following what is explained in the README.
1213
- Increase maximum timeout to 15s from 3s.
1314

1415
## [1.1.0] - 2019-10-27
@@ -22,6 +23,7 @@ https://github.com/ipregistry/ipregistry-python#caching
2223
## [1.0.0] - 2019-07-28
2324
- First public release.
2425

25-
[Unreleased]: https://github.com/ipregistry/ipregistry-javascript/compare/1.1.0...HEAD
26+
[Unreleased]: https://github.com/ipregistry/ipregistry-javascript/compare/2.0.0...HEAD
27+
[2.0.0]: https://github.com/ipregistry/ipregistry-javascript/releases/tag/1.1.0...2.0.0
2628
[1.1.0]: https://github.com/ipregistry/ipregistry-javascript/releases/tag/1.0.0...1.1.0
2729
[1.0.0]: https://github.com/ipregistry/ipregistry-javascript/releases/tag/1.0.0

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,23 @@ folder.
5757

5858
### Caching
5959

60-
The Ipregistry client has built-in support for in-memory caching. The default cache strategy is to memoize up to
60+
This Ipregistry client library has built-in support for in-memory caching. By default caching is disabled.
61+
Below are examples to enable and configure a caching strategy. Once enabled, default cache strategy is to memoize up to
6162
2048 lookups for at most 10min. You can change preferences as follows:
6263

64+
#### Enabling caching
65+
66+
Enable caching by passing an instance of `DefaultCache`:
67+
6368
```python
6469
from ipregistry import DefaultCache, IpregistryClient
6570

6671
client = IpregistryClient("YOUR_API_KEY", cache=DefaultCache(maxsize=2048, ttl=600))
6772
```
6873

69-
or disable caching by passing an instance of `NoCache`:
74+
#### Disabling caching
75+
76+
Disable caching by passing an instance of `NoCache`:
7077

7178
```python
7279
from ipregistry import IpregistryClient, NoCache

ipregistry/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
import json
1818

19-
from .cache import DefaultCache, IpregistryCache
19+
from .cache import IpregistryCache, NoCache
2020
from .model import LookupError
2121
from .request import DefaultRequestHandler, IpregistryRequestHandler
2222

2323
class IpregistryClient:
2424
def __init__(self, keyOrConfig, **kwargs):
2525
self._config = keyOrConfig if isinstance(keyOrConfig, IpregistryConfig) else IpregistryConfig(keyOrConfig)
26-
self._cache = kwargs["cache"] if "cache" in kwargs else DefaultCache()
26+
self._cache = kwargs["cache"] if "cache" in kwargs else NoCache()
2727
self._requestHandler = kwargs["requestHandler"] if "requestHandler" in kwargs else DefaultRequestHandler(self._config)
2828

2929
if not isinstance(self._cache, IpregistryCache):

tests/test_client.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""
2+
Copyright 2019 Ipregistry (https://ipregistry.co).
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
https://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
"""
16+
17+
import unittest
18+
19+
from ipregistry.cache import NoCache
20+
from ipregistry.core import IpregistryClient
21+
22+
class TestIpregistryClient(unittest.TestCase):
23+
def test_defaultclient_cache(self):
24+
"""
25+
Test that default cache is an instance of NoCache
26+
"""
27+
client = IpregistryClient("")
28+
self.assertEqual(True, isinstance(client._cache, NoCache))
29+
30+
if __name__ == '__main__':
31+
unittest.main()

0 commit comments

Comments
 (0)