# Moderately intensive query in multi session perspective project

**URL:** <https://forum.inductiveautomation.com/t/moderately-intensive-query-in-multi-session-perspective-project/94673>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [August 14, 2024, 9:35pm UTC](https://forum.inductiveautomation.com/t/moderately-intensive-query-in-multi-session-perspective-project/94673 "2024-08-14T21:35:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [August 14, 2024, 9:35pm UTC](https://forum.inductiveautomation.com/t/moderately-intensive-query-in-multi-session-perspective-project/94673/1 "2024-08-14T21:35:16Z")

</div>

I am making a production metric dashboard in Perspective. It will be displayed in several locations throughout one department, and support staff may also have the project open to see department progress throughout the day. In summary there will be many sessions open at once all displaying the same data.

The SQL query that populates this view is moderately heavy, and I would like to minimize the number of times it needs to run. I would like to update the data displayed to users every ~5 minutes; I'm less excited about running this query for every open session every 5 minutes.

Is there a way I can run the SQL query once, cache the results, and reference the cache from all the open sessions?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 14, 2024, 9:38pm UTC](https://forum.inductiveautomation.com/t/moderately-intensive-query-in-multi-session-perspective-project/94673/2 "2024-08-14T21:38:57Z")

</div>

Put it in a named query and enable caching?  
The named query cache is determined by the parameters, so as long as you're passing the same parameters you'll hit the cache and avoid the round trip to the DB.

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [August 14, 2024, 9:44pm UTC](https://forum.inductiveautomation.com/t/moderately-intensive-query-in-multi-session-perspective-project/94673/3 "2024-08-14T21:44:23Z")

</div>

> [@paul-griffith](#):
>
> Put it in a named query and enable caching?

That seems obvious in hindsight. Thanks.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 14, 2024, 9:49pm UTC](https://forum.inductiveautomation.com/t/moderately-intensive-query-in-multi-session-perspective-project/94673/4 "2024-08-14T21:49:03Z")

</div>

Note that the cache is relatively "dumb" - that is, if a second session hits the named query while the first query is still executing, the second query will still hit the database, it won't wait for the first query to complete and use the cache. So you can still get multiple executions within the cache duration if executions line up right.

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [August 14, 2024, 10:30pm UTC](https://forum.inductiveautomation.com/t/moderately-intensive-query-in-multi-session-perspective-project/94673/5 "2024-08-14T22:30:59Z")

</div>

That won't be a catastrophe in this case. I don't expect the sessions to synchronized, so I doubt they will be updating at exactly the same time. If they do line up exactly, the database will handle it, but why waste resources when caching is this easy.

> [@paul-griffith](#):
>
> The named query cache is determined by the parameters

I assume this implies that a named query with no parameters will cache for other executions of that named query with no parameters. Is that correct?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 14, 2024, 10:32pm UTC](https://forum.inductiveautomation.com/t/moderately-intensive-query-in-multi-session-perspective-project/94673/6 "2024-08-14T22:32:22Z")

</div>

Yes, exactly.
