@@ -135,28 +135,15 @@ def __init__(self, cached_content_name: str):
135
135
"456".
136
136
"""
137
137
super ().__init__ (resource_name = cached_content_name )
138
-
139
- resource_name = aiplatform_utils .full_resource_name (
140
- resource_name = cached_content_name ,
141
- resource_noun = self ._resource_noun ,
142
- parse_resource_name_method = self ._parse_resource_name ,
143
- format_resource_name_method = self ._format_resource_name ,
144
- project = self .project ,
145
- location = self .location ,
146
- parent_resource_name_fields = None ,
147
- resource_id_validator = self ._resource_id_validator ,
148
- )
149
- self ._gca_resource = gca_cached_content .CachedContent (name = resource_name )
138
+ self ._gca_resource = self ._get_gca_resource (cached_content_name )
150
139
151
140
@property
152
141
def _raw_cached_content (self ) -> gca_cached_content .CachedContent :
153
142
return self ._gca_resource
154
143
155
144
@property
156
145
def model_name (self ) -> str :
157
- if not self ._raw_cached_content .model :
158
- self ._sync_gca_resource ()
159
- return self ._raw_cached_content .model
146
+ return self ._gca_resource .model
160
147
161
148
@classmethod
162
149
def create (
@@ -235,6 +222,10 @@ def create(
235
222
obj ._gca_resource = cached_content_resource
236
223
return obj
237
224
225
+ def refresh (self ):
226
+ """Syncs the local cached content with the remote resource."""
227
+ self ._sync_gca_resource ()
228
+
238
229
def update (
239
230
self ,
240
231
* ,
@@ -265,15 +256,28 @@ def update(
265
256
266
257
@property
267
258
def expire_time (self ) -> datetime .datetime :
268
- """Time this resource was last updated."""
269
- self ._sync_gca_resource ()
259
+ """Time this resource is considered expired.
260
+
261
+ The returned value may be stale. Use refresh() to get the latest value.
262
+
263
+ Returns:
264
+ The expiration time of the cached content resource.
265
+ """
270
266
return self ._gca_resource .expire_time
271
267
272
268
def delete (self ):
269
+ """Deletes the current cached content resource."""
273
270
self ._delete ()
274
271
275
272
@classmethod
276
- def list (cls ):
273
+ def list (cls ) -> List ["CachedContent" ]:
274
+ """Lists the active cached content resources."""
277
275
# TODO(b/345326114): Make list() interface richer after aligning with
278
276
# Google AI SDK
279
277
return cls ._list ()
278
+
279
+ @classmethod
280
+ def get (cls , cached_content_name : str ) -> "CachedContent" :
281
+ """Retrieves an existing cached content resource."""
282
+ cache = cls (cached_content_name )
283
+ return cache
0 commit comments