queryFeatures returns cached features

474
1
Jump to solution
10-21-2022 09:05 AM
MichaelWen_Timmons
Occasional Contributor

This is in JavaScript API 4.21.

I am using queryFeatures to retrieve a recently updated feature to be highlighted and displayed on top of the feature layer from which the layer was queried. This used to work but now queryFeatures is returning old features from before the update. If I clear the browser's cache and reload the page then queryFeatures would return the updated version of the features. I verified from the API that the feature were updated when queryFeatures() was run. It is like the method was run against a cached version of the layer.

This is odd because it is only doing this for three of the layers. The other layers on the same service works fine.

Is there a way to run queryFeatures that forces the layer to get the data from the server and not the cache?

Thanks.

 

 

0 Kudos
1 Solution

Accepted Solutions
JoelBennett
MVP Regular Contributor

One trick you can do is to make sure your query's where clause is always unique.  A common technique to return all features (and it is what it is) is to set the where clause to "1=1".  However, you could substitute any number into that.  To guarantee a unique number every time, which would defeat the browser's cache, you could use something like Date.now() every time.

For example, if your Query object had no where value, you'd put:

var now = Date.now().toString();
query.where = now + "=" + now;

 

Otherwise, if your Query already had a where value, you'd put:

var now = Date.now().toString();
query.where = "(" + query.where + ") AND " + now + "=" + now;

 

View solution in original post

0 Kudos
1 Reply
JoelBennett
MVP Regular Contributor

One trick you can do is to make sure your query's where clause is always unique.  A common technique to return all features (and it is what it is) is to set the where clause to "1=1".  However, you could substitute any number into that.  To guarantee a unique number every time, which would defeat the browser's cache, you could use something like Date.now() every time.

For example, if your Query object had no where value, you'd put:

var now = Date.now().toString();
query.where = now + "=" + now;

 

Otherwise, if your Query already had a where value, you'd put:

var now = Date.now().toString();
query.where = "(" + query.where + ") AND " + now + "=" + now;

 

0 Kudos