4
4
5
5
import logging
6
6
import threading
7
- from threading import local
8
7
from typing import TYPE_CHECKING , Optional , Union
9
8
10
9
from pyatlan .cache .abstract_asset_cache import AbstractAssetCache , AbstractAssetName
17
16
from pyatlan .client .atlan import AtlanClient
18
17
19
18
lock = threading .Lock ()
20
- connection_cache_tls = local () # Thread-local storage (TLS)
21
19
LOGGER = logging .getLogger (__name__ )
22
20
23
21
@@ -44,25 +42,7 @@ class ConnectionCache(AbstractAssetCache):
44
42
def __init__ (self , client : AtlanClient ):
45
43
super ().__init__ (client )
46
44
47
- @classmethod
48
- def get_cache (cls , client : Optional [AtlanClient ] = None ) -> ConnectionCache :
49
- from pyatlan .client .atlan import AtlanClient
50
-
51
- with lock :
52
- client = client or AtlanClient .get_default_client ()
53
- cache_key = client .cache_key
54
-
55
- if not hasattr (connection_cache_tls , "caches" ):
56
- connection_cache_tls .caches = {}
57
-
58
- if cache_key not in connection_cache_tls .caches :
59
- cache_instance = ConnectionCache (client = client )
60
- connection_cache_tls .caches [cache_key ] = cache_instance
61
-
62
- return connection_cache_tls .caches [cache_key ]
63
-
64
- @classmethod
65
- def get_by_guid (cls , guid : str , allow_refresh : bool = True ) -> Connection :
45
+ def get_by_guid (self , guid : str , allow_refresh : bool = True ) -> Connection :
66
46
"""
67
47
Retrieve a connection from the cache by its UUID.
68
48
If the asset is not found, it will be looked up and added to the cache.
@@ -74,11 +54,10 @@ def get_by_guid(cls, guid: str, allow_refresh: bool = True) -> Connection:
74
54
:raises NotFoundError: if the connection cannot be found (does not exist) in Atlan
75
55
:raises InvalidRequestError: if no UUID was provided for the connection to retrieve
76
56
"""
77
- return cls . get_cache () ._get_by_guid (guid = guid , allow_refresh = allow_refresh )
57
+ return self ._get_by_guid (guid = guid , allow_refresh = allow_refresh )
78
58
79
- @classmethod
80
59
def get_by_qualified_name (
81
- cls , qualified_name : str , allow_refresh : bool = True
60
+ self , qualified_name : str , allow_refresh : bool = True
82
61
) -> Connection :
83
62
"""
84
63
Retrieve a connection from the cache by its unique Atlan-internal name.
@@ -92,13 +71,12 @@ def get_by_qualified_name(
92
71
:raises NotFoundError: if the connection cannot be found (does not exist) in Atlan
93
72
:raises InvalidRequestError: if no qualified_name was provided for the connection to retrieve
94
73
"""
95
- return cls . get_cache () ._get_by_qualified_name (
74
+ return self ._get_by_qualified_name (
96
75
qualified_name = qualified_name , allow_refresh = allow_refresh
97
76
)
98
77
99
- @classmethod
100
78
def get_by_name (
101
- cls , name : ConnectionName , allow_refresh : bool = True
79
+ self , name : ConnectionName , allow_refresh : bool = True
102
80
) -> Connection :
103
81
"""
104
82
Retrieve an connection from the cache by its uniquely identifiable name.
@@ -112,7 +90,7 @@ def get_by_name(
112
90
:raises NotFoundError: if the connection cannot be found (does not exist) in Atlan
113
91
:raises InvalidRequestError: if no name was provided for the connection to retrieve
114
92
"""
115
- return cls . get_cache () ._get_by_name (name = name , allow_refresh = allow_refresh )
93
+ return self ._get_by_name (name = name , allow_refresh = allow_refresh )
116
94
117
95
def lookup_by_guid (self , guid : str ) -> None :
118
96
if not guid :
@@ -149,8 +127,8 @@ def lookup_by_name(self, name: ConnectionName) -> None:
149
127
return
150
128
with self .lock :
151
129
results = self .client .asset .find_connections_by_name (
152
- name = name .name ,
153
- connector_type = name .type ,
130
+ name = name .name , # type: ignore[arg-type]
131
+ connector_type = name .type , # type: ignore[arg-type]
154
132
attributes = self .SEARCH_ATTRIBUTES ,
155
133
)
156
134
if not results :
0 commit comments