1- import requests
21from uuid import UUID
32from typing import Optional
43from sempy_labs ._helper_functions import (
5- get_pbi_token_headers ,
6- _get_url_prefix ,
74 get_model_id ,
85 resolve_item_name_and_id ,
96 resolve_workspace_name_and_id ,
7+ _base_api ,
108)
11- from sempy .fabric .exceptions import FabricHTTPException
129from sempy ._utils ._log import log
1310import sempy_labs ._icons as icons
1411
@@ -31,13 +28,12 @@ def enable_query_caching(
3128 enable : bool, default=True
3229 Set to True to enable query caching, or False to disable it.
3330 """
34- prefix = _get_url_prefix ()
35- headers = get_pbi_token_headers ()
31+
3632 (workspace_name , workspace_id ) = resolve_workspace_name_and_id (workspace )
3733 (item_name , item_id ) = resolve_item_name_and_id (
3834 item = dataset , type = "SemanticModel" , workspace = workspace_id
3935 )
40- model_id = get_model_id (item_id = item_id , headers = headers , prefix = prefix )
36+ model_id = get_model_id (item_id = item_id )
4137 if model_id is None :
4238 raise ValueError (f"Failed to retrieve model ID for semantic model '{ item_name } '" )
4339
@@ -48,12 +44,7 @@ def enable_query_caching(
4844
4945 payload = {"queryCachingState" : caching_map .get (enable )}
5046
51- response = requests .post (
52- f"{ prefix } /metadata/models/{ model_id } /caching" , headers = headers , json = payload
53- )
54-
55- if response .status_code != 204 :
56- raise FabricHTTPException (response )
47+ _base_api (request = f"metadata/models/{ model_id } /caching" , method = "internal" , payload = payload , status_codes = 204 )
5748
5849 print (
5950 f"{ icons .green_dot } Query caching has been { 'enabled' if enable else 'disabled' } for the '{ item_name } ' semantic model within the '{ workspace_name } ' workspace."
0 commit comments