TransWikia.com

How to cache a view for all users of a role?

Drupal Answers Asked by ktrev on October 26, 2021

I have a view that displays a map. I need to display 7000 entries on the map.
I have installed solar search API to index the content and have created a view using that.
Still, the loading time for that view is around 1 minute for each user. After the first fetch, then it loads fast for that user since it fetches the data from the cache.

I was wondering whether I can cache the entire view for all users of a specific role.
I tried installing the "Views Custom Cache Tags" module.
But I am a bit lost on how to configure it.
Also not sure whether this will solve my problem or not.

Suggestions, please.

One Answer

To answer the question title and the comment of @Leigh, without going into the details of the complexity of the specific View:

How to cache a view for all users of a role?

Views are cached like any other rendered content. When rendered a View bubbles up the cacheable metadata of Views plugins, like filter or sorting plugins and the rendered content itself.

Additionally there are the three default contexts, as defined in the service container:

core.services.yml:

  required_cache_contexts: ['languages:language_interface', 'theme', 'user.permissions']

The context user.permissions is a hash of all of the user's permissions, which is the result of the roles assigned to a user.

So in the end a View is cached for user roles by default.

Answered by 4k4 on October 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP