Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(parameters): add clear_cache method for providers #1194

Merged

Conversation

heitorlessa
Copy link
Contributor

@heitorlessa heitorlessa commented Apr 29, 2022

Issue number: #1092

Summary

Changes

Please provide a summary of what's being changed

This introduces a new method in each Parameters provider called clear_cache, and a standalone function to clear cache across all providers that is useful for customers using higher level functions.

image

User experience

Please share what the user experience looks like before and after this change

Clearing cache for an individual parameters provider

import pytest

from src import app


@pytest.fixture(scope="function", autouse=True)
def clear_parameters_cache():
    yield
    app.ssm_provider.clear_cache() # This will clear SSMProvider cache

@pytest.fixture
def mock_parameter_response(monkeypatch):
    def mockreturn(name):
        return "mock_value"

    monkeypatch.setattr(app.ssm_provider, "get", mockreturn)

# Pass our fixture as an argument to all tests where we want to mock the get_parameter response
def test_handler(mock_parameter_response):
    return_val = app.handler({}, {})
    assert return_val.get('message') == 'mock_value'

Clearing cache for all providers

import pytest

from aws_lambda_powertools.utilities import parameters
from src import app


@pytest.fixture(scope="function", autouse=True)
def clear_parameters_cache():
    yield
    parameters.clear_caches() # This will clear all providers cache

@pytest.fixture
def mock_parameter_response(monkeypatch):
    def mockreturn(name):
        return "mock_value"

    monkeypatch.setattr(app.ssm_provider, "get", mockreturn)

# Pass our fixture as an argument to all tests where we want to mock the get_parameter response
def test_handler(mock_parameter_response):
    return_val = app.handler({}, {})
    assert return_val.get('message') == 'mock_value'

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.


View rendered docs/utilities/parameters.md

@boring-cyborg boring-cyborg bot added area/utilities documentation Improvements or additions to documentation tests labels Apr 29, 2022
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 29, 2022
@github-actions github-actions bot added the feature New feature or functionality label Apr 29, 2022
@heitorlessa heitorlessa linked an issue Apr 29, 2022 that may be closed by this pull request
2 tasks
@heitorlessa heitorlessa merged commit 3570d7f into aws-powertools:develop Apr 29, 2022
@heitorlessa heitorlessa deleted the fix/parameters-clear-cache branch April 29, 2022 14:36
@heitorlessa heitorlessa changed the title feat(parameters): add clear_cache method for providers fix(parameters): add clear_cache method for providers Apr 29, 2022
@heitorlessa heitorlessa changed the title fix(parameters): add clear_cache method for providers feat(parameters): add clear_cache method for providers Apr 29, 2022
@github-actions github-actions bot added the bug Something isn't working label Apr 29, 2022
heitorlessa added a commit to ran-isenberg/aws-lambda-powertools-python that referenced this pull request May 18, 2022
* develop: (33 commits)
  fix(docs): remove Slack link (aws-powertools#1210)
  docs(roadmap): add new roadmap section (aws-powertools#1204)
  fix(batch): missing space in BatchProcessingError message (aws-powertools#1201)
  fix(batch): docstring fix for success_handler() record parameter (aws-powertools#1202)
  chore(deps): bump email-validator from 1.1.3 to 1.2.1 (aws-powertools#1199)
  docs(layer): upgrade to 1.25.10
  chore: include regression in changelog
  chore: bump to 1.25.10
  feat(parameters): add clear_cache method for providers (aws-powertools#1194)
  chore(ci): changelog pre-generation to fetch tags from origin
  revert(parser): Add missing fields for SESEvent (aws-powertools#1027) (aws-powertools#1190)
  fix(parser): Add missing fields for SESEvent (aws-powertools#1027)
  fix(data-classes): Add missing SES fields and (aws-powertools#1045)
  fix(event_handler): exception_handler to handle ServiceError exceptions (aws-powertools#1160)
  chore(deps-dev): bump flake8-bugbear from 22.1.11 to 22.4.25 (aws-powertools#1156)
  chore(deps-dev): bump mypy from 0.942 to 0.950 (aws-powertools#1162)
  chore(deps-dev): bump flake8-eradicate from 1.2.0 to 1.2.1 (aws-powertools#1158)
  chore(deps): bump github/codeql-action from 1 to 2 (aws-powertools#1154)
  chore(ci): post release on tagged issues too
  fix(event_handler): Allow for event_source support (aws-powertools#1159)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation feature New feature or functionality size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants