001/* 002 * This library is part of OpenCms - 003 * The Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software GmbH & Co. KG, please see the 018 * company website: https://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: https://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.loader.imagecache; 029 030import java.time.Instant; 031import java.util.Objects; 032 033/** 034 * Backend-neutral metadata for an image cache entry.<p> 035 */ 036public final class CmsImageCacheEntry { 037 038 /** The cache key. */ 039 private final String m_key; 040 041 /** The entry length. */ 042 private final long m_length; 043 044 /** The last modification time, if available. */ 045 private final Instant m_lastModified; 046 047 /** An optional opaque backend revision. */ 048 private final String m_revision; 049 050 /** 051 * Creates an image cache entry.<p> 052 * 053 * @param key the cache key 054 * @param length the entry length 055 * @param lastModified the last modification time, or {@code null} 056 * @param revision an opaque backend revision, or {@code null} 057 */ 058 public CmsImageCacheEntry(String key, long length, Instant lastModified, String revision) { 059 060 m_key = Objects.requireNonNull(key, "key"); 061 if (key.isEmpty()) { 062 throw new IllegalArgumentException("The image cache entry key must not be empty."); 063 } 064 if (length < 0) { 065 throw new IllegalArgumentException("The image cache entry length must not be negative."); 066 } 067 m_length = length; 068 m_lastModified = lastModified; 069 m_revision = revision; 070 } 071 072 /** 073 * Returns the cache key.<p> 074 * 075 * @return the cache key 076 */ 077 public String getKey() { 078 079 return m_key; 080 } 081 082 /** 083 * Returns the last modification time.<p> 084 * 085 * @return the last modification time, or {@code null} 086 */ 087 public Instant getLastModified() { 088 089 return m_lastModified; 090 } 091 092 /** 093 * Returns the entry length.<p> 094 * 095 * @return the entry length 096 */ 097 public long getLength() { 098 099 return m_length; 100 } 101 102 /** 103 * Returns the opaque backend revision.<p> 104 * 105 * @return the backend revision, or {@code null} 106 */ 107 public String getRevision() { 108 109 return m_revision; 110 } 111}