Select to view content in your preferred language

Set and update cache control longest time (cacheMaxAge) for layers and tables

657
1
Jump to solution
09-17-2024 05:35 PM
Labels (1)
miro_aus
Emerging Contributor

Using ArcGIS Online user interface, it is possible to set / update Cache Control longest time. Default is 30 seconds, longest is 1 hour.

This can be done under Cache Control in Settings tab for Feature Layer (hosted) and Table (hosted) with Source: Feature Service.

I am publishing tables and feature layers programmatically using ArcGIS API for Python. I can't find a way to set the Cache Control value when publishing or update it later.

I did find it as property which I can access, but not update. Simplified example of code variations I have tried:

items = user.items()
item = items[0]
table = item.tables[0]
print(table.properties.cacheMaxAge)
cache_definition = {"cacheMaxAge": 600}
result = table.manager.update_definition(cache_definition)
# result = table.manager.add_to_definition(cache_definition)
print(result)
 
Printing cacheMaxAge does print out the actual value set / updated via interface (in seconds, e.g. 3600 for 1 hour). Result value is "{'success': True}". But the cacheMaxAge value does not update.
 
How can I set and/or update Cache Control (cacheMaxAge) using ArcGIS API for Python?
0 Kudos
1 Solution

Accepted Solutions
EarlMedina
Esri Regular Contributor

The way you do this is at the Feature Service level. In the API, it is done via a FeatureLayerCollection object. So, you would update your example to something like this:

 

from arcgis.features import FeatureLayerCollection

items = user.items()
item = items[0]
flc = FeatureLayerCollection.fromitem(item)
flc.manager.update_definition({"cacheMaxAge":600})

 

 This appears to round up to 15 minutes, however, because I think only certain intervals are supported.

View solution in original post

1 Reply
EarlMedina
Esri Regular Contributor

The way you do this is at the Feature Service level. In the API, it is done via a FeatureLayerCollection object. So, you would update your example to something like this:

 

from arcgis.features import FeatureLayerCollection

items = user.items()
item = items[0]
flc = FeatureLayerCollection.fromitem(item)
flc.manager.update_definition({"cacheMaxAge":600})

 

 This appears to round up to 15 minutes, however, because I think only certain intervals are supported.