Skip to content

Commit

Permalink
Add public invalidate_cache() function, check its behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
AbrilRBS committed Dec 23, 2024
1 parent e1f6567 commit 90e025a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions conan/api/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def __str__(self):
def __repr__(self):
return str(self)

def invalidate_cache(self):
self.caching = {}


class MultiPackagesList:
def __init__(self):
Expand Down
15 changes: 13 additions & 2 deletions test/integration/command_v2/custom_commands_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,11 @@ def mycommand(conan_api, parser, *args, **kwargs):


class TestCommandsRemoteCaching:
def test_custom_command_with_subcommands(self):
def test_remotes_cache(self):
complex_command = textwrap.dedent("""
import json
from conan.cli.command import conan_command
from conan.api.output import ConanOutput
@conan_command()
def mycache(conan_api, parser, *args, **kwargs):
Expand All @@ -445,6 +446,15 @@ def mycache(conan_api, parser, *args, **kwargs):
deps_graph = conan_api.graph.load_graph_requires(["pkg/0.1"], None, host, build,
None, remotes, None, None)
conan_api.graph.analyze_binaries(deps_graph, None, remotes=remotes)
# Now invalidate the cache and see how it breaks
try:
remotes[0].invalidate_cache()
deps_graph = conan_api.graph.load_graph_requires(["pkg/0.1"], None, host, build,
None, remotes, None, None)
conan_api.graph.analyze_binaries(deps_graph, None, remotes=remotes)
except Exception as e:
ConanOutput().warning(f"Cache invalidated, as expected: {e}")
""")

c = TestClient(default_server_user=True)
Expand All @@ -457,4 +467,5 @@ def mycache(conan_api, parser, *args, **kwargs):
c.run("upload * -r=default -c")
c.run("remove * -c")
c.run("mycache")
# Does not break, caching is working
# Does not break unexpectedly, caching is working
assert "WARN: Cache invalidated, as expected: Invalid URL 'broken" in c.out

0 comments on commit 90e025a

Please sign in to comment.