使用varyByParam和UriTemplate的WCF RESTful服务

时间:2011-11-03 19:01:30

标签: asp.net wcf caching

当我还使用UriTemplate进行RESTful WCF服务时,我无法使用varyByParam来缓存工作。但是,当我使用普通查询字符串参数时,varyByParam的行为正确。

[OperationContract]
[WebGet(UriTemplate = "/{appId}/CacheTest/{param}")]
[WebCache(Duration=300, VaryByParam="param")]
string CacheTest(string appId, string param);

所有CacheTest都返回当前时间。我将其称为以下组合:/1/CacheTest/1/2/CacheTest/1/1/CacheTest/2/2/CacheTest/2。每次通话都会返回不同的时间。

当我这样做时:

[OperationContract]
[WebGet]
[WebCache(Duration=300, VaryByParam="param")]
string CacheTest(string appId, string param);

/CacheTest?appId=1&param=1/CacheTest?appId=2&param=1都会返回相同的时间。 /CacheTest?appId=1&param=2/CacheTest?appId=2&param=2也是如此。

如何使第一种情况与第二种情况相同?我尝试了VaryByCustom,但我无法访问GetVaryByCustomString中的参数,除非它们在查询字符串中。

0 个答案:

没有答案