I'm using a store with an ajax proxy to read via php and json from a mysql database. Everything works fine, but there is a general problem: After loading the store it holds the current data of the database. If there is a change in the database (mysql), the store doesn't recognize. Here is a simplified example:
Let's say each beer has a function drink() which decreases the amount of the beer glas by 100ml and the new amount of beer is sent via update to the php file.
Person 1 calls drink() of a glas (ID: 1) with 200ml. In his store and on the server the new amount of the beer in the glas is 100ml. Person2 on another mobile/pc syncs his store and also drinks 100ml from the same beer glas (ID: 1). Now the glas is empty (at the server and person2s store), but person1s store still has a value of 100ml.
How to check if local store is in sync with multi-access online database
Code:
me.beerStore = Ext.create('App.store.Beer', {
model: 'App.model.Beer',
proxy: {
type: 'ajax',
api: {
read: 'beer.php?method=read',
create: 'beer.php?method=create',
update: 'beer.php?method=update',
destroy: 'beer.php?method=destroy'
},
reader: {
type: 'json',
rootProperty: 'data',
messageProperty: 'messsage',
successProperty: 'success'
},
writer: {
type: 'json',
writeAllFields: false,
rootProperty: 'data'
}
});
Let's say each beer has a function drink() which decreases the amount of the beer glas by 100ml and the new amount of beer is sent via update to the php file.
Person 1 calls drink() of a glas (ID: 1) with 200ml. In his store and on the server the new amount of the beer in the glas is 100ml. Person2 on another mobile/pc syncs his store and also drinks 100ml from the same beer glas (ID: 1). Now the glas is empty (at the server and person2s store), but person1s store still has a value of 100ml.
My question: When person1 calls drink(), his local store decreases the beer to 0ml but online this beer now has -100ml. Is there a best practice by only using the store, how to check if the local store is still in sync with the database?
How to check if local store is in sync with multi-access online database
Aucun commentaire:
Enregistrer un commentaire