001/*
002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     Nuxeo - initial API and implementation
011 *
012 */
013package org.nuxeo.ecm.core.convert.cache;
014
015import java.io.Serializable;
016import java.util.Map;
017
018import org.nuxeo.ecm.core.api.blobholder.BlobHolder;
019
020/**
021 * Simple helper to handle cache key generation.
022 *
023 * @author tiry
024 */
025public class CacheKeyGenerator {
026
027    // Utility class.
028    private CacheKeyGenerator() {
029    }
030
031    public static String computeKey(String converterName, BlobHolder blobHolder, Map<String, Serializable> parameters) {
032        StringBuilder sb = new StringBuilder();
033        sb.append(converterName);
034        sb.append(":");
035        sb.append(blobHolder.getHash());
036        if (parameters != null) {
037            for (String key : parameters.keySet()) {
038                sb.append(":").append(key);
039                sb.append(":").append(String.valueOf(parameters.get(key)));
040            }
041        }
042        return sb.toString();
043    }
044
045}