Server-Side Caching for the China Company Search API

Reuse authorized China company search results with keys that account for request inputs, language, page, and freshness.

ArticlesPublished by ChinaValidatePublished December 3, 2026Last updated December 3, 2026

Find Chinese companies by name or keyword. Use a matching record’s legal name or Unified Social Credit Code for a profile lookup.

View API documentationAPI workspace
Server-Side Caching for the China Company Search API

A procurement portal opens the same supplier review several times in one afternoon. Each view needs to show which companies a name search previously returned. If all those views send a fresh paid query upstream, the system can spend credits and still give the buyer several answers with no clear observation date. A private server-side cache can reuse a recent result under an explicit freshness policy, while the review record identifies when the data was obtained.

Use a cache scoped to the access context of the intended users. Build the key from the request values that can change the result, including search keyword, mode, page and language. Allow a buyer to ask for a fresh result when needed. Distinguish available observations from failures, and preserve the timestamp of the original result when it is reused. Follow the product's terms and the HTTP response directives applicable to your deployment. ChinaValidate company search API · ChinaValidate terms

Identity of a search observation

The documented Company Search operation is a GET request. It accepts keyword and optional search_scope, page and language. A broad search and a precise search can answer different questions. A result for page one cannot stand in for a result on a later page. If a user enters a similar name with a different character, preserve the input you actually sent. A cache that merges legal names based on appearance can serve misleading candidates.

Include an opaque internal account or tenant boundary in the key. Use the context that makes it appropriate for a second user to see the same result, such as an organization with a shared verification account and permissions. Recheck authorization when a result is read. Treat a shared search for the same string across unrelated customers as two contexts. Keep the bearer credential out of the key, logs, and browser requests. A namespace based only on the supplied company name omits both the authorized context and the request options.

Consider an exact company profile request after a candidate is selected. It uses a separate operation with its own documented input. Keep search and profile observations separate, even when a search result supplies the name or code needed to fetch the profile. A search response may be useful evidence of the candidates the reviewer saw. A profile supplies a different observation about the confirmed legal entity. ChinaValidate company profile API

The small helper below shows a key for one documented operation. It assumes that the organization scope and request parameters are already validated by the application, including the product's documented values for language and mode. A version marker lets you change the layout without accidentally finding a value written by an older key design.

import { createHash } from "node:crypto";

export function companySearchCacheKey({
  authorizationScope, keyword, searchScope = "all",
  page = 1, language = "zh-CN"
}) {
  const keyParts = [
    "company-search:v1",
    authorizationScope,
    keyword,
    searchScope,
    page,
    language
  ];
  const digest = createHash("sha256")
    .update(JSON.stringify(keyParts), "utf8")
    .digest("hex");
  return "company-search:" + digest;
}

Use the values the caller actually sends upstream. If the application trims the input before sending, use that trimmed value in the key and retain the supplied form separately where you need an audit trail. If the first page is omitted from the request, using the documented default gives consistent keys for equivalent requests. Avoid using this key alone as evidence of a hit. An observed record still needs the operation, relevant input, response time, and outcome to be understandable by the reviewer.

Eligible results and freshness rules

HTTP caching and storing an observation for an authorized application are related parts of the design. RFC 9111 explains how shared HTTP caches handle responses to requests with Authorization. Such responses need an explicit permitted directive before a shared cache uses them to satisfy another request. Do not assume that an authenticated API result can be cached by a general CDN. Inspect the actual header behavior and respect any restrictions. In the application, reuse a result only within a permitted scope and retention policy. RFC 9111 authenticated-request caching

The freshest usable hit is not necessarily the right one for a decision if the rule for this request demands a new observation. Define what age is acceptable for routine candidate selection and when a profile must be checked again. Pick a period that matches your process rather than applying the same duration to every screening operation. The search interface can show the date when it is using evidence already obtained. A user-requested refresh can then be documented as a new query instead of a silent effect of viewing a different tab.

Observation Handling in the application
Recent successful search in the same permitted context Reuse the original evidence and show its observation time
Completed search without a result Keep a dated empty result if the policy permits, with its own freshness rule
Request fails because of authentication, balance, or an input problem Show a request failure and leave any previous observation distinct
Network interruption leaves an attempt uncertain Record its uncertainty and check existing evidence before resending
Buyer requests a fresh observation for a new decision Make a new request under the current evidence and billing policy
A result is restricted against storage or reuse Respect the restriction when handling the request and response

An empty result deserves special care. A typo or a short keyword can legitimately lead to no records. If your policy permits negative caching, a short separate window can avoid many repeats while leaving room for a corrected request. A service error is a different state. Treating it as a cached empty result makes an outage look like evidence about a company and can hide a problem from the operator. Display any older usable result only as a prior observation, with the time it was seen.

For a supplier list prepared this morning, a team might allow a candidate search to be reused across several views of the same review. For a buyer attempting to confirm a disputed code on a later day, that same result may only be historical context. A readable record can show the observation time and a reuse decision for this purpose, together with the original search input. This makes freshness intelligible without displaying an internal cache timer as if it were the validity of a business registration.

When a newer response replaces the working cache entry, use the observation date rather than time of the cache write to tell which response is newer. Requests can finish out of order. A short application interval can still surface older data if a delayed save overwrites a newer result. Keep each observation's own time and only use the result that meets the stated selection rule.

Request reuse, coalescing, and cost

ChinaValidate's published pricing rules say that completed requests can use credits, including completed searches with no matches. A repeated completed call is charged separately. Cache hits are internal activity in your own system. Distinguish them in metrics from externally dispatched requests and from responses that actually completed at the provider. That separation helps reconcile costs with the number of lookups the portal appears to have handled. ChinaValidate API pricing and billing

Imagine a review page receiving four simultaneous requests for the same candidate list under a permitted access scope, all before the first upstream response arrives. An existing cache has no value for any of them. A single in-flight request shared by those equivalent callers can avoid four redundant external calls. Coordinate this within the same scope and key. A one-process implementation only covers that process, whereas multiple workers may need synchronization in a shared store or routing under the same application capacity policy. Once an attempt fails or finishes, clear the temporary in-flight entry.

Keep a hard separation between an in-flight request and durable evidence. If the worker stops after sending the request, a later worker can have an uncertain attempt. Processing through a new off-screen request can create extra chargeable work. Record enough correlation data to reconcile the prior effort before deciding whether to retry. If a temporary cache value is removed when it expires, retain evidence already attached to a purchase under the applicable policy. Users should still be able to see what supported their earlier decision.

Tests around a cache hit

Begin with two identical requests within a controlled test harness and one fixture response. Check that the second read preserves the first observation time and uses no external transport call. Change the request language, scope, page, and internal authorization scope one at a time. Each change should produce a different key. Check a new request after the accepted interval, as well as a deliberate refresh while the result is still within that interval. Add a completed empty search and an application error to ensure that their displays remain different.

Test an in-flight failure with two simultaneous callers. They should each see the incomplete outcome, and a fresh action later should be able to start a new attempt. Include a permissions change between two reads of the same record and confirm that the working cache does not bypass the new access decision. Lastly, inspect a record from an earlier purchase. Even after the working result changes, the reviewer should be able to identify the exact observation that was used, its scope, and whether that earlier request reused an existing result.