Copyright 2011-2016 Terracotta, Inc. Copyright 2011-2016 Oracle America Incorporated Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
/** * Copyright 2011-2016 Terracotta, Inc. * Copyright 2011-2016 Oracle America Incorporated * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */
package javax.cache.expiry; import javax.cache.configuration.Factory; import javax.cache.configuration.FactoryBuilder; import java.io.Serializable;
An ExpiryPolicy that defines the expiry Duration of a Cache Entry based on the last time it was updated. Updating includes created and changing (updating) an entry.
Author:Greg Luck, Brian Oliver
See Also:
Since:1.0
/** * An {@link ExpiryPolicy} that defines the expiry {@link Duration} * of a Cache Entry based on the last time it was updated. Updating * includes created and changing (updating) an entry. * * @author Greg Luck * @author Brian Oliver * @since 1.0 * @see ExpiryPolicy */
public final class ModifiedExpiryPolicy implements ExpiryPolicy, Serializable {
The serialVersionUID required for Serializable.
/** * The serialVersionUID required for {@link java.io.Serializable}. */
public static final long serialVersionUID = 201305101602L;
The Duration a Cache Entry should be available before it expires.
/** * The {@link Duration} a Cache Entry should be available before it expires. */
private Duration expiryDuration;
Params:
  • expiryDuration – the Duration a Cache Entry should exist be before it expires after being modified
/** * Constructs an {@link ModifiedExpiryPolicy} {@link ExpiryPolicy}. * * @param expiryDuration the {@link Duration} a Cache Entry should exist be * before it expires after being modified */
public ModifiedExpiryPolicy(Duration expiryDuration) { this.expiryDuration = expiryDuration; }
Obtains a Factory for a Modified ExpiryPolicy.
Params:
  • duration – The expiry duration
Returns:a Factory for a Modified ExpiryPolicy.
/** * Obtains a {@link Factory} for a Modified {@link ExpiryPolicy}. * * @param duration The expiry duration * @return a {@link Factory} for a Modified {@link ExpiryPolicy}. */
public static Factory<ExpiryPolicy> factoryOf(Duration duration) { return new FactoryBuilder.SingletonFactory<ExpiryPolicy>(new ModifiedExpiryPolicy(duration)); }
{@inheritDoc}
/** * {@inheritDoc} */
@Override public Duration getExpiryForCreation() { //for newly created entries we use the specified expiry duration return expiryDuration; }
{@inheritDoc}
/** * {@inheritDoc} */
@Override public Duration getExpiryForAccess() { //accessing a cache entry has no affect on the current expiry duration return null; }
{@inheritDoc}
/** * {@inheritDoc} */
@Override public Duration getExpiryForUpdate() { //when a cache entry is modified, we return the specified expiry duration, //ignoring the current expiry duration return expiryDuration; }
{@inheritDoc}
/** * {@inheritDoc} */
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((expiryDuration == null) ? 0 : expiryDuration.hashCode()); return result; }
{@inheritDoc}
/** * {@inheritDoc} */
@Override public boolean equals(Object object) { if (this == object) { return true; } if (object == null) { return false; } if (!(object instanceof ModifiedExpiryPolicy)) { return false; } ModifiedExpiryPolicy other = (ModifiedExpiryPolicy) object; if (expiryDuration == null) { if (other.expiryDuration != null) { return false; } } else if (!expiryDuration.equals(other.expiryDuration)) { return false; } return true; } }