How to write code that runs once

Make hicnExists a nullable static class-level variable. Test to see if it’s null when your function is called. If it’s null, run your query and set the value. Once the value is set, the query will not run again for the remainder of the current transaction.

If you want to cache the result between transactions, then I recommend setting a session cookie or making use of server-side session variables.

Browse More Popular Posts

Leave a Comment