question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: support clearing/scoped caches for testing

See original GitHub issue

Use case

We’re testing our code with mocked AWS services using moto (rather than replacing/patching the calls entirely), and it works well. However, powertools provides various caches that are great for production, but cause unintended linkage/interference between tests. We’re hitting this particularly in aws_lambda_powertools.utilities.parameters.get_secret, but it applies to other parts of that module, and likely any other global caches built into this package.

It’d be nice to be able to run tests isolated without having to manually write force_fetch=running_in_tests() or similar everywhere.

Solution/User Experience

Some method for clearing caches. For instance, a global aws_powertools_lambda.clear_caches() or aws_powertools_lambda.utilities.parameters.clear_caches(). Tests could then have set-up that calls that to ensure each one has a fresh environment.

Alternative solutions

Alternatives:

  • an environment variable that disables caching entirely, which can be set during tests runs (not so good because the deployed behaviour differs)
  • using contextvars to have the “global” caches actually be scope-able (this seems complicated)

Acknowledgment

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
huonwcommented, Apr 5, 2022

As workaround for now we’ve got a pytest fixture that pokes into the internals of this package:

import aws_lambda_powertools.utilities.parameters.base

# FIXME: https://github.com/awslabs/aws-lambda-powertools-python/issues/1092
@pytest.fixture(autouse=True)
def clear_powertools_cache() -> None:
    for v in aws_lambda_powertools.utilities.parameters.base.DEFAULT_PROVIDERS.values():
        v.store.clear()
0reactions
github-actions[bot]commented, Apr 29, 2022

This is now released under 1.25.10 version!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Server and Browser Cache - Support Center - WP Engine
Learn about WP Engine server caching and how to purge cache. ... from server caching by default on all sites to help ensure...
Read more >
clear cache for a single page | Firefox Support Forum
It is not possible to clear the cache for just one website, any clear operation that involves a cache clears the full cache....
Read more >
Support more options in cache-control extension #142 - GitHub
At this moment caching supports just maxAge and scope hints. it is a good start but there are much more features which should...
Read more >
Caching in GitLab CI/CD
A cache is one or more files a job downloads and saves. Subsequent jobs that use the same cache don't have to download...
Read more >
The Cache API: A quick guide - web.dev
The Cache API was created to enable service workers to cache network requests so that they can provide fast responses, regardless of network ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found