@yxw007/translate 0.0.1-alpha.2 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
+ // translate v0.0.1 Copyright (c) 2024 Potter<aa4790139@gmail.com> and contributors
1
2
  (function (global, factory) {
2
3
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
4
  typeof define === 'function' && define.amd ? define(['exports'], factory) :
@@ -6822,7 +6823,7 @@ ${toHex(hashedRequest)}`;
6822
6823
  this.engines.set(engine.name, engine);
6823
6824
  }
6824
6825
  translate(text, options) {
6825
- const { from, to, engine = "google", cache_time = 60 } = options;
6826
+ const { from, to, engine = "google", cache_time = 60 * 1000 } = options;
6826
6827
  //1. Check if engine exists
6827
6828
  if (!this.engines.has(engine)) {
6828
6829
  throw new Error(`Engine ${engine} not found`);
@@ -6835,6 +6836,10 @@ ${toHex(hashedRequest)}`;
6835
6836
  throw new Error(`Language ${to} not found`);
6836
6837
  }
6837
6838
  const key = `${from}:${to}:${engine}:${text}`;
6839
+ //3. If the cache is matched, the cache is used directly
6840
+ if (cache.get(key)) {
6841
+ return cache.get(key)?.value;
6842
+ }
6838
6843
  const engineInstance = this.engines.get(engine);
6839
6844
  if (!engineInstance) {
6840
6845
  throw new Error(`Engine ${engine} not found`);