public IActionResult SearchMusic(string key, int index) { if (string.IsNullOrEmpty(key) || index < 1) { return(new JsonResult(new { code = -1, msg = "参数异常" })); } key = WebUtility.UrlDecode(key); var pageIndex = index; var pageSize = 10; var cacheKey = string.Format("{0}_{1}_{2}", key, pageSize, pageIndex); var result = NetEaseMusicSearchResultCache.Get(cacheKey); if (result == null || result.Total <= 0) { result = service.Search(key, pageIndex, pageSize).Result; if (result != null && result.Total > 0) { NetEaseMusicSearchResultCache.Set(cacheKey, result); } } return(new JsonResult(new { code = 0, data = result })); }
public void SearchMethod() { var result = _service.Search("李白", 1, 20).Result; Assert.IsNotNull(result); }