You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
server.views.populate_image uses a cached image, with no way to clear the cache #568
I have a series of dashboards with a live SQL connection. The workflow for these dashboards is to run a nightly refresh of the underlying data table, take a screenshot of the dashboard, and email it out to users.
The issue is that after refreshing the SQL connection, server.views.populate_image returns an image of the dashboard from before it is refreshed. (e.g., if I have data for 1/1/2020, truncate that table overnight, insert data for 1/2/2020, then use views.populate_image, it will still show 1/1/2020 data, even though that data is truncated from the underlying data table as Tableau is caching the image of the dashboard).
Here is a snippet of the offending code:
import logging
import tableauserverclient as TSC
workbook_name = "name of workbook containing view"
view_name = "view to print"
report_filter = "dashboard filter value"
filter_name = "dashboard filter name"
report_export_file_name = "file path + file name of image to be generated"
tableau_auth = [censored]
with server.auth.sign_in_with_personal_access_token(tableau_auth):
all_workbooks = TSC.Pager(server.workbooks.get)
workbook = [
wb
for wb in all_workbooks
if wb.name == workbook_name and wb.project_name == workbook_project
][0]
logging.info(f"Found workbook: {workbook_name}")
# request views from workbook and find first matching view
server.workbooks.populate_views(workbook)
view = [v for v in workbook.views if v.name == view_name][0]
logging.info(f"Downloaded view to memory: {view_name}")
# request image of view and download it locally
# maxage = max age of image cached in minutes
# shortest interval that you can use is one minute
image_req_option = TSC.ImageRequestOptions(maxage=1)
if report_filter:
image_req_option.vf(filter_name, report_filter)
server.views.populate_image(view, image_req_option)
# save file
with open(report_export_file_name, "wb") as view_png:
view_png.write(view.image)
logging.info(f"Saved view to {report_export_file_name}")
What I've tried:
Setting maxage to 1 minute, doesn't seem to work as intended, as even running this script >1 minutes after the SQL update sometimes shows a cached view.
Using workbooks.refresh method. Doesn't work as this seems to be expecting a data extract, not live SQL connection.
Here's a way you can toss out the cache and force a fresh PNG / PDF download:
Add a parameter to your workbook. Let's assume you name it 'cache_buster'. You might even reference this parameter value in a hidden sheet on your dashboard so you ensure it gets used.
In the code you have that downloads the PNG or PDF for your visual, specify 'cache_buster' as one of your filters
here is the important part: be sure to change the value set for 'cache_buster' in your code each time you want to void the old cached version and get a fresh copy.
So if you run your code the first time, maybe your cache_buster=1. If you download the image again 30 minutes later, you may receive a cached version of what you just pulled.
But, if you make cache_buster=2, then you will trick Tableau into thinking it is passing in a new filter value and it voids the cache on your visual.
That parameter doesn't really do anything in your workbook -- it's simply there to invalidate the unwanted cache on your visual.
Reacted by MRSHUAI, kylemcleland-zz and Denis Glinkin
For this workaround, you would have to add the update parameter while editing the workbook normally - either in Desktop or Web Authoring. It can't be edited through tsc.
Activity
divinorum-webb commentedon Mar 8, 2020
Here's a way you can toss out the cache and force a fresh PNG / PDF download:
So if you run your code the first time, maybe your cache_buster=1. If you download the image again 30 minutes later, you may receive a cached version of what you just pulled.
But, if you make cache_buster=2, then you will trick Tableau into thinking it is passing in a new filter value and it voids the cache on your visual.
That parameter doesn't really do anything in your workbook -- it's simply there to invalidate the unwanted cache on your visual.
maxwqx commentedon Apr 14, 2020
@divinorum-webb I am new to the TSC. Can you give a sample code about how to add the parameter of "cache_buster".
efarmun commentedon Jul 27, 2021
@divinorum-webb nice workaround advice but can you advise the way to update parameter on server side using tsc (python) ?
Thanks.
https://community.tableau.com/s/question/0D54T00000C6AwkSAF/is-there-a-way-to-edit-a-parameter-and-its-values-within-tableau-server
jacalata commentedon Nov 10, 2021
For this workaround, you would have to add the update parameter while editing the workbook normally - either in Desktop or Web Authoring. It can't be edited through tsc.