File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed
generative_ai/context_caching Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change 1111# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212# See the License for the specific language governing permissions and
1313# limitations under the License.
14-
1514import os
1615
1716from typing import Generator
Original file line number Diff line number Diff line change 1919def update_context_cache (cache_id : str ) -> str :
2020 # [START generativeaionvertexai_gemini_update_context_cache]
2121 import vertexai
22- import datetime
22+ from datetime import datetime as dt
23+ from datetime import timezone as tz
24+ from datetime import timedelta
2325
2426 from vertexai .preview import caching
2527
@@ -31,8 +33,13 @@ def update_context_cache(cache_id: str) -> str:
3133
3234 cached_content = caching .CachedContent (cached_content_name = cache_id )
3335
34- # Update the expiration time by 1 hour
35- cached_content .update (ttl = datetime .timedelta (hours = 1 ))
36+ # Option1: Update the context cache using TTL (Time to live)
37+ cached_content .update (ttl = timedelta (hours = 3 ))
38+ cached_content .refresh ()
39+
40+ # Option2: Update the context cache using specific time
41+ next_week_utc = dt .now (tz .utc ) + timedelta (days = 7 )
42+ cached_content .update (expire_time = next_week_utc )
3643 cached_content .refresh ()
3744
3845 print (cached_content .expire_time )
You can’t perform that action at this time.
0 commit comments