我不会这样做的。如果用户提出/回答了 5,000 个问题,则初始登录将永远持续。如果要缓存,请按请求缓存。它也将使编写 Web 服务驱动程序更容易。
用您自己的本地函数调用包装每个 Web 服务调用。在实际执行 Web 服务调用之前,请检查数据库以查看您是否已完成此调用。如果有,请检查超时以查看是否已过期。如果过期,或者没有设置做服务调用,并存储到数据库。
编辑
一些伪代码。函数名的组成:
string get_question(questionId)
{
SQL = " SELECT data FROM cache
WHERE service='StackOverflow'
AND proceedure='get_question'
AND username='?'
AND parameters = '?'
AND updated > DATEADD(h, ?, GETDATE())";
// check to see if it exists in db and is not expired
question = db(SQL, currentUser(), questionId, 2); // single parameter is question id, 2 hour timeout
// if question is not null, then return the question from the cache.
if (question != NULL && question != "")
{
return question;
}
//otherwise do the webservice call to get the data.
question = WebServiceCall('get_question',questionId);
// store to database, delete if exists first.
db("DELETE from cache where service='StackOverflow' AND proceedure='get_question' AND username='?' AND parameters = '?'", currentUser(), questionId, 2
db("INSERT INTO cache (service,procedure,parameters,username,data) VALUES(...)");
}