I have this WPF application using NHibernate and lazy data loading. I also use Microsoft Sync framework to sync data to and from a central database server. So what happens is that when I modify data on the central database server and sync it with the WPF client app, I can't get the latest data to be displayed to the UI since NHibernate has cached it already. So I need to restart the WPF application to be able to display the latest synched data.
I need a solution to refresh NHibernate data on the WPF app. How can I do this?
The first level cache is only active within a given session, so if you use a new session each time you attempt to retrieve the object you should get the latest results (given you don't have the second level cache configured).
Related
We have a blazor server application in production and the issue is that users usually are filling forms while spending time on other browser tabs, and they leave the blazor server tab open for hours. When they come back to the tab, the connection to the server is lost and they have to reload the page. The issue is that at refresh they loose the data that they added in the application inputs which creates a bad user experience.
I looked into this question but is seems that the solution involves page reloading.
I there any way I can automatically reconnect to the server without refreshing the page ?
One solution for this would be to use the browsers storage, either the session or local storage (I'm pretty sure session storage would be lost on disconnect though I'm not 100% sure) here is Microsoft's documentation on browser storage.
Whenever they fill something on the form out you push it to the browser's storage and if for whatever reason they lose connection and reconnect you check their browser for any data and pull it.
Just remember that if you use local storage they can open multiple tabs and have access to the same data.
From what I've seen the usual recommendation is to use Blazored Local Storage.
Can also use cookies to accomplish the same effect as well.
I don't think so. You wouldn't want the server to be maintaining the state of dead pages indefinitely.
If these users can be identified (for example by logging them in), then it's trivial to keep state. You can use a SQL database to store a JSON string of the current state of the input model, for example. Or you can use a singleton service with data keyed to the user.
I've got a stored procedure that loads some data (about 59k items) and it takes 30 seconds. This SP must be called when the application starts. I was wondering if there's a reasonable way to invalidate the Redis cache entry via SQL ...any suggestion?
Thanks
Don't do it from your SQL, do the invalidation / (re)loading to Redis from your application.
The loading of this data into your application should be done by a separate component/service/module/part of your application. So that part should have all the responsibility of handling the needed data, including (re)loading it into the app, invalidating and reloading into Redis and so on. You should see your Redis server as an extension of your application cached data and not of your sql server data. That's why you should not link your relational database to your Redis. If you are going to change how you save this data into Redis that should not affect the SQL part, but only the application, and actually only the part of your application specialized with this.
I am developing a WPF application using NHibernate to communicate with a PostgreSQL Database.
The only caching provider that works on a desktop app is Bamboo Prevalence (correct me if I am wrong). Given that every computer running my application will have different Session Factory, my application retrieves stale data from the cache.
My question is, how can I tell NHibernate/Prevalence to look at the timestamp of when the data was last updated, and if the cache is stale, refresh it?
Well, I found out that there is no way the Second Level cache can know if the database was changed outside Nhibernate/Cache, so what I did was creating a new column 'Timestamp' on all my tables.
On my queries, I first select the timestamp of the db using Session.Cachemode(CacheMode.Ignore) to get the timestamp of the db and I compare with the result from the cache. In the case the timestamps differ, I invalidate the cache for that query and run it again.
About the SysCache, even knowing it 'can work' on a WPF desktop app, I was not keen to use System.Web.Cache as my application would need the the complete .Net Framework instead of the Client Profile. I did a search and for my happiness someone wrote a Nhiberate cache proviver that implements (System.Runtime.Caching), witch is not a ASP.Net component. If anyone is interested you can find the source at:
https://github.com/Leftyx/nhcontrib/tree/master/src/NHibernate.Caches/MemoryCache
Well that is a property that you could set at the cache level and expire items according to your applications needs and then have the cache. Ncache is a possible L2 cache provider for NHibernate. NCache ensures that its cache is consistent across multiple servers and all cache updates are synchronized correctly so no data integrity issues arise. To learn more please visit:
http://www.alachisoft.com/ncache/nhibernate-l2cache-index.html
I use Core Data to maintain a persistent store, and the database can grow quite large. My users with larger databases on iPad 1s don't complete the lightweight migration in time for the process to complete before the app is killed by the iOS for hanging.
What I want to do is every time the server starts up, check to see if the database needs to be migrated (I can't find a method for this on NSPersistentStoreCoordinator), if it does hold the server startup process until the database is upgraded and display a spinner on screen, then move forward with the server startup process once it is. The best way to do this seems to be to add a - (BOOL) upgradeStoreNeedsUpgrade method in the server startup method, but I can't find a way to check. I don't see methods on NSPersistentStoreCoordinator or NSPersistentStore to check the compatibility of a a database at a given URL with a given managed object model.
Is my solution the right way, and if so, how can I check if the managed object model is compatible with the SQLite file at a given URL?
You could try wrapping the core data lightweight migration code in a dispatch block. This should spin it off to a background thread so you can get past the Application Start Watchdog thats probably killing your app. Its either that or you are running the device out of memory.
I have two applications(web and a desktop app) that uses entity framework which use a common sql server database. They have unit of work pattern implemented and it keeps the context in the session or in the relevant thread. My question is how to update context of another application when one application updates something on the database ?
As an example let say the windows service has added some row to a table. How can the web application context get that one at the same time it is inserted.
Context in scenario of a web application should only last per the request. From what I see, you have to implement something as an event from database level as that seems to be the common place. This can be done using Triggers
In your scenario, you should perform following steps (just doing a drawing board scenario)
Add triggers at database level for each table, which will basically throw an event to the application layer.
Somehow extract those triggers into stored procedures, so that you can use with EF
Thereafter, implement a layer that sits on both the application whose primary responsibility is to notify the user of a change in the database by other application and then update the request by clicking a button(which in turn update the context). Basically the database level trigger, triggers something on the respective UI.
The meat of the work lies in the third point. You can achieve it in many ways. Alternatives are writing a service that polls another service (which accepts alerts from db trigger) for checking the modifications. so the logical separation could be like db --> service that accepts the change notification --> service that polls the notification service --> application
Above works logically and theoretically but hope it helps you out and I would be keen to know how you go about doing this.