-
-
Notifications
You must be signed in to change notification settings - Fork 793
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # README.md # gradle.properties # src/main/kotlin/cn/yiiguxing/plugin/translate/action/TranslateDocumentationAction.kt # src/main/kotlin/cn/yiiguxing/plugin/translate/documentation/HtmlTranslator.kt # src/main/kotlin/cn/yiiguxing/plugin/translate/documentation/TranslateDocumentationTask.kt # src/main/kotlin/cn/yiiguxing/plugin/translate/provider/TranslatingDocumentationProvider.kt
- Loading branch information
Showing
128 changed files
with
423 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/kotlin/cn/yiiguxing/plugin/translate/service/CacheService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package cn.yiiguxing.plugin.translate.service | ||
|
||
import cn.yiiguxing.plugin.translate.trans.Lang | ||
import cn.yiiguxing.plugin.translate.trans.Translation | ||
import cn.yiiguxing.plugin.translate.util.LruCache | ||
import com.intellij.openapi.components.Service | ||
import com.intellij.openapi.components.ServiceManager | ||
|
||
@Service | ||
class CacheService { | ||
|
||
private val memoryCache = LruCache<CacheKey, Translation>(1024) | ||
|
||
fun putMemoryCache(text: String, srcLang: Lang, targetLang: Lang, translatorId: String, translation: Translation) { | ||
memoryCache.put(CacheKey(text, srcLang, targetLang, translatorId), translation) | ||
if (Lang.AUTO == srcLang) { | ||
memoryCache.put(CacheKey(text, translation.srcLang, targetLang, translatorId), translation) | ||
} | ||
if (Lang.AUTO == targetLang) { | ||
memoryCache.put(CacheKey(text, srcLang, translation.targetLang, translatorId), translation) | ||
} | ||
if (Lang.AUTO == srcLang && Lang.AUTO == targetLang) { | ||
memoryCache.put(CacheKey(text, translation.srcLang, translation.targetLang, translatorId), translation) | ||
} | ||
} | ||
|
||
fun getMemoryCache(text: String, srcLang: Lang, targetLang: Lang, translatorId: String): Translation? { | ||
return memoryCache[CacheKey(text, srcLang, targetLang, translatorId)] | ||
} | ||
|
||
fun getMemoryCacheSnapshot(): Map<CacheKey, Translation> { | ||
return memoryCache.snapshot | ||
} | ||
|
||
/** | ||
* CacheKey | ||
*/ | ||
data class CacheKey(val text: String, val srcLang: Lang, val targetLang: Lang, val translator: String = "unknown") | ||
|
||
companion object { | ||
val instance: CacheService | ||
get() = ServiceManager.getService(CacheService::class.java) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.