HOW TO
By default, the cache duration for Cache Control is set to 30 seconds. The cache duration can be adjusted to manage resource usage in the browser when consuming a hosted feature layer on ArcGIS Online through the Settings page of the hosted feature layer or table. However, ArcGIS API for Python allows updating the cache duration without accessing ArcGIS Online, which is especially useful when multiple layers need to be edited and a list of their item IDs is available.
To do so, the FeatureLayerCollection object can be used to access the hosted feature layer or table's REST endpoint to allow users to edit the JSON definition for the cacheMaxAge parameter.
from arcgis.features import FeatureLayerCollection gis = GIS("<ORGANIZATION_URL>", "username", "password")
from arcgis.features import FeatureLayerCollection gis = GIS("Home")
#To specify an item based on the user's content list: items = gis.items() item = items[0] flc = FeatureLayerCollection.fromitem(item)
#To specify a specific item: item = gis.content.get("<Item_ID>") flc = FeatureLayerCollection.fromitem(item)
flc.manager.update_definition({"cacheMaxAge":600})
The following is a sample of a working standalone script for a specific item.
from arcgis.features import FeatureLayerCollection gis = GIS("www.arcgis.com", "username123", "password123") item = gis.content.get("sdfn32rncwei8hfqwn") flc = FeatureLayerCollection.fromitem(item) flc.manager.update_definition({"cacheMaxAge":600})
Get help from ArcGIS experts
Download the Esri Support App