When my app loads I need to establish the membership "status" of a user. Their "status" will determine how the app behaves. Do I query the database for the "status" value each time the app loads, or can it be sourced from cache? The "status" could change for a user, not not very often. Thanks.

Your app always needs to "phone home" to query the actual member status with your server.

Otherwise, someone could log in twice, delete their account in one session and merrily carry on using their 'account' in the other session.

Sure, you could use the cached version if the user is just browsing, but as soon as they attempt some 'membership required' step, you need to verify membership at that point.

Sourcing the user's "status" from the cache can be a good approach in this case, as long as you have a reliable mechanism to keep the cached data up-to-date. Since the "status" doesn't change very often, caching it can help reduce the number of database queries and improve the app's performance. However, you'll need to consider how often the "status" changes, how to handle stale cache data, and the impact of serving outdated information to the user.

You can cache the user's "status" since it doesn't change often. On app load, check the cache first; if it's outdated or missing, then query the database for the current status and update the cache. This way, you minimize database queries while ensuring the app reflects any status changes when needed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.