Skip to content

Commit b7d1ff3

Browse files
committed
add caching
1 parent a73025d commit b7d1ff3

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

multiversx_sdk_cli/cli_shared.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import logging
55
import sys
66
from argparse import FileType
7+
from functools import cache
78
from pathlib import Path
89
from typing import Any, Text, Union, cast
910

@@ -507,6 +508,7 @@ def get_current_nonce_for_address(address: Address, proxy_url: Union[str, None])
507508
return proxy.get_account(address).nonce
508509

509510

511+
@cache
510512
def get_chain_id(chain_id: str, proxy_url: str) -> str:
511513
if chain_id and proxy_url:
512514
fetched_chain_id = _fetch_chain_id(proxy_url)
@@ -523,6 +525,7 @@ def get_chain_id(chain_id: str, proxy_url: str) -> str:
523525
return _fetch_chain_id(proxy_url)
524526

525527

528+
@cache
526529
def _fetch_chain_id(proxy_url: str) -> str:
527530
network_provider_config = config.get_config_for_network_providers()
528531
proxy = ProxyNetworkProvider(url=proxy_url, config=network_provider_config)

multiversx_sdk_cli/config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
from dataclasses import dataclass
3+
from functools import cache
34
from pathlib import Path
45
from typing import Any
56

@@ -32,6 +33,7 @@ def get_dependency_url(key: str, tag: str, platform: str) -> str:
3233
return url_template.replace("{TAG}", tag)
3334

3435

36+
@cache
3537
def get_value(name: str) -> str:
3638
_guard_valid_name(name)
3739
data = get_active()
@@ -41,6 +43,7 @@ def get_value(name: str) -> str:
4143
return value
4244

4345

46+
@cache
4447
def get_address_hrp() -> str:
4548
return get_value("default_address_hrp")
4649

@@ -146,14 +149,17 @@ def get_defaults() -> dict[str, Any]:
146149
}
147150

148151

152+
@cache
149153
def get_proxy_url() -> str:
150154
return get_value("proxy_url")
151155

152156

157+
@cache
153158
def get_explorer_url() -> str:
154159
return get_value("explorer_url")
155160

156161

162+
@cache
157163
def get_confirmation_setting() -> bool:
158164
confirmation_value = get_value("ask_confirmation")
159165
if confirmation_value.lower() in ["true", "yes", "1"]:
@@ -176,6 +182,7 @@ def resolve_config_path() -> Path:
176182
return GLOBAL_CONFIG_PATH
177183

178184

185+
@cache
179186
def read_file() -> dict[str, Any]:
180187
config_path = resolve_config_path()
181188
if config_path.exists():
@@ -210,6 +217,7 @@ class MxpyConfig:
210217
ask_confirmation: bool
211218

212219
@classmethod
220+
@cache
213221
def from_active_config(cls) -> "MxpyConfig":
214222
return cls(
215223
address_hrp=get_address_hrp(),

0 commit comments

Comments
 (0)