How to use the ipinfo.cache.default.DefaultCache function in ipinfo

To help you get started, we’ve selected a few ipinfo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ipinfo / python / ipinfo / handler.py View on Github external
"""Initialize the Handler object with country name list and the cache initialized."""
        self.access_token = access_token
        self.countries = self._read_country_names(kwargs.get("countries_file"))
        self.request_options = kwargs.get("request_options", {})
        if "timeout" not in self.request_options:
            self.request_options["timeout"] = self.REQUEST_TIMEOUT_DEFAULT

        if "cache" in kwargs:
            self.cache = kwargs["cache"]
        else:
            cache_options = kwargs.get("cache_options", {})
            if "maxsize" not in cache_options:
                cache_options["maxsize"] = self.CACHE_MAXSIZE
            if "ttl" not in cache_options:
                cache_options["ttl"] = self.CACHE_TTL
            self.cache = DefaultCache(**cache_options)