type cacheEntry … type certCache … var globalCertCache … type activeCert … // active increments the number of references to the entry, wraps the // certificate in the entry in an activeCert, and sets the finalizer. // // Note that there is a race between active and the finalizer set on the // returned activeCert, triggered if active is called after the ref count is // decremented such that refs may be > 0 when evict is called. We consider this // safe, since the caller holding an activeCert for an entry that is no longer // in the cache is fine, with the only side effect being the memory overhead of // there being more than one distinct reference to a certificate alive at once. func (cc *certCache) active(e *cacheEntry) *activeCert { … } // evict removes a cacheEntry from the cache. func (cc *certCache) evict(e *cacheEntry) { … } // newCert returns a x509.Certificate parsed from der. If there is already a copy // of the certificate in the cache, a reference to the existing certificate will // be returned. Otherwise, a fresh certificate will be added to the cache, and // the reference returned. The returned reference should not be mutated. func (cc *certCache) newCert(der []byte) (*activeCert, error) { … }