Disable cache on class-listings.php

Hello, I have the listing component in the main page which shows new added listings by date, but I notice that class-listings-php file loads the listings in cache and not the real time new listings.

I have comment the following code in order to work better:

// Get cached IDs.
				$listing_ids = null;

				if ( 'random' !== $this->order ) {
					$listing_ids = hivepress()->cache->get_cache( array_merge( $query->get_args(), [ 'fields' => 'ids' ] ), 'models/listing' );

					if ( is_array( $listing_ids ) ) {
						$query = Models\Listing::query()->filter(
							[
								'status' => 'publish',
								'id__in' => $listing_ids,
							]
						)->order( 'id__in' )
						->limit( count( $listing_ids ) );
					}
				}

Is there any way to disable it by a filter to avoid code changes? How much is the time configured in the cache for this query?

Thanks and best regards!

1 Like

Hi,

If you mean the UI block settings, we recommend leaving the cache, because the cache is updated only after the listing is updated or a new listing is created, in all other options the cache is not updated. If this does not work correctly for you, try re-saving the listing. Also, if the last recommendation did not help, I recommend disabling all third-party plugins and caching, or contacting your hosting provider, as there may be caching on their side.

1 Like

Hi Andrii,

Thank you for your response.

Following your recommendations, I have identified the problem. The issue was caused by a snippet of code that updates the listing date upon user request.

I resolved the problem by clearing the cache after updating the dates with the following code in the snippet:

hivepress()->cache->delete_cache( null , 'models/listing');

By this way I leave the class-listings.php file without any modification.

Do you think this is a good solution? I have tried to use delete_post_cache in order to clear only the affected listing, but I don’t have found enough documentation to understand the functions parameters. I have only the listing id and this call doesn’t work:

hivepress()->cache->delete_post_cache( $listing_id , 'models/listing');

Thanks and best regards,

1 Like

Hi,

Please note that the listing cache is cleared after the listing is updated or created. It all depends on where exactly you added this delete_cache; if it is an infrequent action, then there shouldn’t be an issue.

1 Like

Thanks Andrii,

It is an infrequent and controlled action. It works fine for me.

Thanks again and very best regards!

1 Like

Awesome that you found the solution :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.