开发者

Client-side web service caching policy for a slow and unreliable service

开发者 https://www.devze.com 2023-02-12 04:31 出处:网络
I\'m trying to figure out the best way to cache a slow and unreliable service.Right开发者_StackOverflow now, every time the service goes down, all page requests start to take a long time because the c

I'm trying to figure out the best way to cache a slow and unreliable service. Right开发者_StackOverflow now, every time the service goes down, all page requests start to take a long time because the cache never gets filled and the service is queried every time. The service is not providing data that is essential to the page. How should I cache this to make it work well for me?

I don't think it really matters, but I'm using PHP 5 and and the service is SOAP.


I'd serialize() the received data structure and write it to a file.

If the PHP app requests new data, I'd unserialize() the data from the file and return it directly. After a certain amount of time, the next request reloads the resource from remote and serialize() again to the file.

Update:

How about injecting up-front in every relevant page some default Json data, which the client uses as a reply if the service doesn't reply fast enough?


I'm implementing a webservice cache for php at the moment.

It's no rocket science. All is need is a persistence (I choose sqlite because access to the sqlite file ist faster then to a "normal" file. RAMdisk would probably even faster) and a simple class or function that controls reading and writing access to the persistence.

Using a file instead of calling the service saves about 95% of time :)


Five years later, Netflix has solved this problem with their very useful "Hystrix" library.

https://github.com/Netflix/Hystrix

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号