File tree Expand file tree Collapse file tree 4 files changed +46
-6
lines changed
Expand file tree Collapse file tree 4 files changed +46
-6
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
61622048 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
6469from ipregistry import DefaultCache, IpregistryClient
6570
6671client = 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
7279from ipregistry import IpregistryClient, NoCache
Original file line number Diff line number Diff line change 1616
1717import json
1818
19- from .cache import DefaultCache , IpregistryCache
19+ from .cache import IpregistryCache , NoCache
2020from .model import LookupError
2121from .request import DefaultRequestHandler , IpregistryRequestHandler
2222
2323class 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 ):
Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments