Skip to content

Commit

Permalink
缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
YiiGuxing committed Jun 1, 2016
1 parent 80395cd commit 1381603
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/cn/yiiguxing/plugin/translate/Translation.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ public void search(String query, Callback callback) {
mCurrentTask = null;
}

QueryResult cache = mCache.get(query);
QueryResult cache;
synchronized (mCache) {
cache = mCache.get(query);
}
if (cache != null) {
if (callback != null) {
callback.onQuery(query, cache);
Expand Down Expand Up @@ -73,7 +76,9 @@ public void run() {
HttpGet httpGet = new HttpGet(BASIC_URL + URLEncoder.encode(query, "UTF-8"));
result = httpClient.execute(httpGet, new YouDaoResponseHandler());
if (result != null && result.getErrorCode() != QueryResult.ERROR_CODE_FAIL) {
mCache.put(query, result);
synchronized (mCache) {
mCache.put(query, result);
}
}
} catch (Exception e) {
LOG.error("query...", e);
Expand Down

0 comments on commit 1381603

Please sign in to comment.