GNU social JP
  • FAQ
  • Login
GNU social JPは日本のGNU socialサーバーです。
Usage/ToS/admin/test/Pleroma FE
  • Public

    • Public
    • Network
    • Groups
    • Featured
    • Popular
    • People

Conversation

Notices

  1. Embed this notice
    Ivan Sagalaev :flag_wbw: (isagalaev@mastodon.social)'s status on Saturday, 24-Feb-2024 17:33:49 JST Ivan Sagalaev :flag_wbw: Ivan Sagalaev :flag_wbw:

    Looking for a #Python library that would cache the most fresh responses of HTTP requests and only return cached ones in case of connection or server errors.

    requests-cache doesn't do the trick: it either returns stale responses or crashes on connection errors.

    Doesn't have to be HTTP-specific, really. Think of it as a general memoization with failover. But lru_cache from stdlib also doesn't work as it prefers the cached value over the available fresh one.

    Last chance before I write my own!

    In conversation about a year ago from mastodon.social permalink
    • clacke likes this.
    • Embed this notice
      Paarth :verified: (paarth@mastodon.pirate.lgbt)'s status on Saturday, 24-Feb-2024 17:33:56 JST Paarth :verified: Paarth :verified:
      in reply to

      @isagalaev you don't need another library! From the docs for lru_cache: https://docs.python.org/3/library/functools.html#functools.lru_cache

      > The original underlying function is accessible through the __wrapped__ attribute. This is useful for introspection, for bypassing the cache

      So you can easily do something along the lines of:

      try:
      cached_func.__wrapped__(*args)
      except SomeSpecificError:
      cached_func(*args)

      In conversation about a year ago permalink

      Attachments

      1. Domain not in remote thumbnail source whitelist: docs.python.org
        functools — Higher-order functions and operations on callable objects
        from ../about.html
        Source code: Lib/functools.py The functools module is for higher-order functions: functions that act on or return other functions. In general, any callable object can be treated as a function for t...
      clacke likes this.
    • Embed this notice
      clacke (clacke@libranet.de)'s status on Saturday, 24-Feb-2024 17:33:59 JST clacke clacke
      in reply to
      • Paarth :verified:

      @paarth But if the inner function succeeds, it won't seed the cache.

      @isagalaev

      In conversation about a year ago permalink
    • Embed this notice
      ashwinvis has not (ashwinvis@mastodon.acc.sunet.se)'s status on Saturday, 24-Feb-2024 22:21:28 JST ashwinvis has not ashwinvis has not
      in reply to

      @isagalaev
      There you go

      https://github.com/requests-cache

      The org has caching for both requests and aiohttp package.

      Edit: aaah I didn't see that you have tried it already. I was fairly happy with the aiohttp one. It can be configured to cache only if an OK status is obtained.

      You can look here for pointers.

      https://codeberg.org/ashwinvis/pelican-aio-planet/src/branch/main/pelican/plugins/aio_planet/planet.py#L41

      In conversation about a year ago permalink
      clacke likes this.

Feeds

  • Activity Streams
  • RSS 2.0
  • Atom
  • Help
  • About
  • FAQ
  • TOS
  • Privacy
  • Source
  • Version
  • Contact

GNU social JP is a social network, courtesy of GNU social JP管理人. It runs on GNU social, version 2.0.2-dev, available under the GNU Affero General Public License.

Creative Commons Attribution 3.0 All GNU social JP content and data are available under the Creative Commons Attribution 3.0 license.