class CredentialsCache {

    private final int maximumCacheSizeBytes;
    private final LinkedHashMap<Credentials, Byte> linkedHashMap;
    private final LinkedList<Credentials> linkedList;

    private int currentCacheSizeBytes;

    /**
     * Constructor
     *
     * @param maximumCacheSizeBytes maximum cache size in bytes
     */
    public CredentialsCache(int maximumCacheSizeBytes) {
        this.maximumCacheSizeBytes = maximumCacheSizeBytes;
        linkedHashMap = new LinkedHashMap<>();
        linkedList = new LinkedList<>();
    }

    /**
     * Method to add a Credentials to the cache
     *
     * <p>A credential that exceeds maximumCacheSizeBytes is not cached
     *
     * @param credentials credential
     */
    public synchronized void add(Credentials credentials) {<FILL_FUNCTION_BODY>}

    /**
     * Method to return whether the cache contains the Credentials
     *
     * @param credentials credentials
     * @return true if the set contains the Credential, else false
     */
    public synchronized boolean contains(Credentials credentials) {
        return linkedHashMap.containsKey(credentials);
    }

    /**
     * Method to remove a Credentials from the cache
     *
     * @param credentials credentials
     * @return true if the Credentials existed and was removed, else false
     */
    public synchronized boolean remove(Credentials credentials) {
        if (linkedHashMap.remove(credentials) != null) {
            linkedList.remove(credentials);
            currentCacheSizeBytes -= credentials.toString().getBytes(StandardCharsets.UTF_8).length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * Method to get the maximum cache size in bytes
     *
     * @return the maximum cache size in bytes
     */
    public int getMaximumCacheSizeBytes() {
        return maximumCacheSizeBytes;
    }

    /**
     * Method to get the current cache size in bytes
     *
     * @return the current cache size in bytes
     */
    public synchronized int getCurrentCacheSizeBytes() {
        return currentCacheSizeBytes;
    }
}

        int credentialSizeBytes = credentials.toString().getBytes(StandardCharsets.UTF_8).length;

        // Don't cache the entry since it's bigger than the maximum cache size
        // Don't invalidate other entries
        if (credentialSizeBytes > maximumCacheSizeBytes) {
            return;
        }

        // Purge old cache entries until we have space or the cache is empty
        while (((currentCacheSizeBytes + credentialSizeBytes) > maximumCacheSizeBytes)
                && (currentCacheSizeBytes > 0)) {
            Credentials c = linkedList.removeLast();
            linkedHashMap.remove(c);
            currentCacheSizeBytes -= credentialSizeBytes;
            if (currentCacheSizeBytes < 0) {
                currentCacheSizeBytes = 0;
            }
        }

        linkedHashMap.put(credentials, (byte) 1);
        linkedList.addFirst(credentials);
        currentCacheSizeBytes += credentialSizeBytes;
    
<no_super_class>