阅读文本 / Reading text
This paper uses synthetic samples to demonstrate the processing method. The code has been verified using examples in an isolated environment; this does not guarantee effectiveness for all real-world files or products. Before processing important files, please retain the original copies and verify them against the boundaries and acceptance criteria outlined in this document.
“Save” may look the same across two projects, but its translation, capitalization, and context can differ. Using the original text’s hash as the unique cache key makes it easy to reuse a project’s translation in another project, or even across tenants. Cache utilization isn’t just about hit rate; first, you must define under what conditions identical results are permissible for reuse.
cache key should represent a single translation decision
must at least take into account the source language, target language, terminology version, model or translation strategy version, and scope of use. When context influences the translation, contextual identifiers should also be included. Even if model names are identical, this does not guarantee that the server-side implementation will remain unchanged; to ensure reproducible results, you should record your strategy version along with the actual task information, rather than assuming that a single name is sufficient to lock down all behavior.
Below is an example of local cache key composition. It does not invoke any translation interface, nor does it specify
OmniDoc (Product Entry)
the internal cache implementation.
uses structured serialization to avoid concatenation ambiguities
import hashlib
import json
def cache_key(tenant, text, source_lang, target_lang, glossary, policy):
record = {"tenant": tenant, "text": text, "source": source_lang,
"target": target_lang, "glossary": glossary, "policy": policy}
raw = json.dumps(record, ensure_ascii=False, sort_keys=True,
separators=(",", ":")).encode("utf-8")
return hashlib.sha256(raw).hexdigest()
args = ("demo-a", "保存", "zh", "en", "terms-v1", "ui-v1")
first = cache_key(*args)
assert first == cache_key(*args)
assert first != cache_key("demo-b", *args[1:])
assert first != cache_key("demo-a", "保存", "zh", "ja", "terms-v1", "ui-v1")
assert first != cache_key("demo-a", "保存", "zh", "en", "terms-v2", "ui-v1")
assert len(first) == 64
simple usage
text + language + version
, you will encounter the problem of unclear field boundaries. Structured serialization clarifies field names and value boundaries; a fixed key order and delimiter ensure that the same record yields stable byte sequences. Here, we only demonstrate this fixed protocol; when modifying the serialization rules in the future, the cache namespace should be upgraded in sync.
After a hit, the availability status must still be checked.
cache entries may originate from a failed, canceled, or unreviewed task. A hit on the key does not necessarily mean the result can be delivered directly. The entry should also record its status, creation time, source task, and, when necessary, quality flags. Old cached data resulting from terminology revisions may be retained for historical reference but should no longer be treated as current results under the new policy.
changes
Does this example generate a different key
reason
tenant differs from
is
Avoid reuse scope confusion
Different target languages
is
The translation target has been changed
Different terminology versions
is
The terminology decision has been changed
input and policy are both identical
no
allows querying existing results
hash does not equal the encryption or access control
cannot assume that the body has already been desensitized simply because the cache key is SHA-256. Common short phrases may be enumerated, and cached content still requires access permissions and retention policies. A tenant ID embedded in the key can only provide namespace isolation; it does not replace permission checks at query time.
uniformly removes spaces, punctuation, or digits in pursuit of a higher hit rate, and may even merge texts that are not originally identical. Normalization rules should be explicitly defined and tested with counterexamples that alter semantics; one should not rely solely on the number of calls saved.
enables reuse to serve delivery
If OmniDoc is used as the document translation entry point, the outer-level task orchestration can also retain the input version and acceptance records. Whether to reuse existing results should be determined by your task agreement; this paper does not infer whether the platform employs the same caching strategy, nor does it guarantee that repeated submissions will not generate new tasks or charges.
Reference:
Python hashlib
。
- 1 -
Updated 2026-10-08