55from typing import Any , Generic , List , Optional , Sequence , TypeVar , overload
66
77import requests
8- from typing_extensions import Self
98
109from .context import Context
1110from .urls import Url
@@ -79,8 +78,6 @@ def __init__(self, ctx: Context, path: str, /, **attributes):
7978class ActiveSequence (ABC , Generic [T ], Sequence [T ]):
8079 """A sequence for any HTTP GET endpoint that returns a collection."""
8180
82- _cache : Optional [List [T ]]
83-
8481 def __init__ (self , ctx : Context , path : str , uid : str = "guid" ):
8582 """A sequence abstraction for any HTTP GET endpoint that returns a collection.
8683
@@ -97,27 +94,16 @@ def __init__(self, ctx: Context, path: str, uid: str = "guid"):
9794 self ._ctx = ctx
9895 self ._path = path
9996 self ._uid = uid
100- self ._cache = None
10197
10298 @abstractmethod
10399 def _create_instance (self , path : str , / , ** kwargs : Any ) -> T :
104100 """Create an instance of 'T'."""
105101 raise NotImplementedError ()
106102
107- def reload (self ) -> Self :
108- """Reloads the collection from Connect.
109-
110- Returns
111- -------
112- Self
113- """
114- self ._cache = None
115- return self
116-
117- def _fetch (self ) -> List [T ]:
103+ def fetch (self ) -> List [T ]:
118104 """Fetch the collection.
119105
120- Fetches the collection directly from Connect. This operation does not effect the cache state .
106+ Fetches the collection from Connect.
121107
122108 Returns
123109 -------
@@ -134,42 +120,23 @@ def _to_instance(self, result: dict) -> T:
134120 path = posixpath .join (self ._path , uid )
135121 return self ._create_instance (path , ** result )
136122
137- @property
138- def _data (self ) -> List [T ]:
139- """Get the collection.
140-
141- Fetches the collection from Connect and caches the result. Subsequent invocations return the cached results unless the cache is explicitly reset.
142-
143- Returns
144- -------
145- List[T]
146-
147- See Also
148- --------
149- cached
150- reload
151- """
152- if self ._cache is None :
153- self ._cache = self ._fetch ()
154- return self ._cache
155-
156123 @overload
157124 def __getitem__ (self , index : int ) -> T : ...
158125
159126 @overload
160127 def __getitem__ (self , index : slice ) -> Sequence [T ]: ...
161128
162129 def __getitem__ (self , index ):
163- return self ._data [index ]
130+ return self .fetch () [index ]
164131
165132 def __len__ (self ) -> int :
166- return len (self ._data )
133+ return len (self .fetch () )
167134
168135 def __str__ (self ) -> str :
169- return str (self ._data )
136+ return str (self .fetch () )
170137
171138 def __repr__ (self ) -> str :
172- return repr (self ._data )
139+ return repr (self .fetch () )
173140
174141
175142class ActiveFinderMethods (ActiveSequence [T ], ABC ):
@@ -213,4 +180,4 @@ def find_by(self, **conditions: Any) -> Optional[T]:
213180 Optional[T]
214181 The first record matching the conditions, or `None` if no match is found.
215182 """
216- return next ((v for v in self ._data if v .items () >= conditions .items ()), None )
183+ return next ((v for v in self .fetch () if v .items () >= conditions .items ()), None )
0 commit comments