rhino/src/org/mozilla/javascript/commonjs/module/provider/DefaultUrlConnectionExpiryCalculator.java
raw symbols SCIP| 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | |
| 5 | package org.mozilla.javascript.commonjs.module.provider; |
| 6 | |
| 7 | import java.io.Serializable; |
| 8 | import java.net.URLConnection; |
| 9 | |
| 10 | /** |
| 11 | * The default heuristic for calculating cache expiry of URL-based resources. |
| 12 | * It is simply configured with a default relative expiry, and each invocation |
| 13 | * of {@link #calculateExpiry(URLConnection)} returns |
| 14 | * {@link System#currentTimeMillis()} incremented with the relative expiry. |
| 15 | * @author Attila Szegedi |
| 16 | * @version $Id: DefaultUrlConnectionExpiryCalculator.java,v 1.3 2011/04/07 20:26:12 hannes%helma.at Exp $ |
| 17 | */ |
| 18 | public class DefaultUrlConnectionExpiryCalculator |
| 19 | implements UrlConnectionExpiryCalculator, Serializable |
| 20 | { |
| 21 | private static final long serialVersionUID = 1L; |
| 22 | |
| 23 | private final long relativeExpiry; |
| 24 | |
| 25 | /** |
| 26 | * Creates a new default expiry calculator with one minute relative expiry. |
| 27 | */ |
| 28 | public DefaultUrlConnectionExpiryCalculator() { |
| 29 | this(60000L); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Creates a new default expiry calculator with the specified relative |
| 34 | * expiry. |
| 35 | * @param relativeExpiry the fixed relative expiry, in milliseconds. |
| 36 | */ |
| 37 | public DefaultUrlConnectionExpiryCalculator(long relativeExpiry) { |
| 38 | if(relativeExpiry < 0) { |
| 39 | throw new IllegalArgumentException("relativeExpiry < 0"); |
| 40 | } |
| 41 | this.relativeExpiry = relativeExpiry; |
| 42 | } |
| 43 | |
| 44 | public long calculateExpiry(URLConnection urlConnection) { |
| 45 | return System.currentTimeMillis() + relativeExpiry; |
| 46 | } |
| 47 | } |