Feature - Implemented Cache store items so that shop_amount() can save server hits

zarqon

Well-known member
Currently, mafia hits the KoL server every time shop_amount() is called. This is because the amount in your shop can change at any time, which makes sense.

However, since that number can only decrease, it makes sense for mafia to cache the existence of items in your shop. For someone who only has Knob goblin pants in their store, shop_amount(every other item) will always be 0, no matter how many of those pants someone buys.

Anytime mafia hits the shop, items in the shop would be flagged. Non-flagged items may return 0 without hitting the server. Mafia would need to update the flags when adding/removing items to/from the shop.

For scripts that mess with items, the work needed to save these server hits in the script is not something your average scripter would feel up to doing -- in a foreach of get_inventory() for example, they may check shop_amount(). I'd guess that quite a few server hits could be saved were this change implemented.
 

lostcalpolydude

Developer
Staff member
As far as I can tell, prices were already cached back when this feature was requested. However, int [item] get_shop() was added in 11483.
 

Winterbay

Active member
Sorry for the thread-jack here but is there any way to get the price you have set on a thing in your store?
 

Bale

Minion
As far as I can tell, prices were already cached back when this feature was requested. However, int [item] get_shop() was added in 11483.

int [item] get_shop() does not fulfill this feature request since that value is not persistent. Every time a script is called, get_shop() will need to hit the server to check quantities all over again. I wouldn't be surprised if the feature is rejected because get_shop() fulfills most of the need, but it is not the same thing.
 

lostcalpolydude

Developer
Staff member
int [item] get_shop() does not fulfill this feature request since that value is not persistent. Every time a script is called, get_shop() will need to hit the server to check quantities all over again. I wouldn't be surprised if the feature is rejected because get_shop() fulfills most of the need, but it is not the same thing.

It does not hit the server, except the first time. The same is true of shop_amount(). Using either one will cache results that the other one can use. Unless you have some specific scenario where it is hitting the server every time.
 

Theraze

Active member
Doesn't it need to hit the server to see if it's been bought, if it's an item in your shop that has some quantity? If it doesn't check to see if you still have it... then it should. The only items which should be cached are the ones which you don't have any of in the shop, which therefore should never increase in quantity magically...
 

Bale

Minion
It does not hit the server, except the first time. The same is true of shop_amount(). Using either one will cache results that the other one can use. Unless you have some specific scenario where it is hitting the server every time.

I stand corrected. This feature is much more than thoroughly implemented.
 

Theraze

Active member
I wrote it on the basis of mafia providing accurate information. :) The other _amount functions all provide accurate information without needing to restart. If shop_amount required quitting mafia complete with logout script, and then relaunching complete with hitting the api and whatever else your login script does, to provide another accurate shop_amount result... that's what it takes. :D
 
Top