
com.landawn.abacus.cache.AbstractQueryCache Maven / Gradle / Ivy
The newest version!
/*
* Copyright (C) 2015 HaiYang Li
*
* 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 com.landawn.abacus.cache;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import com.landawn.abacus.pool.AbstractPoolable;
import com.landawn.abacus.util.ClassUtil;
import com.landawn.abacus.util.IOUtil;
import com.landawn.abacus.util.N;
import com.landawn.abacus.util.Options.Cache;
import com.landawn.abacus.util.Properties;
// TODO: Auto-generated Javadoc
/**
*
* @author Haiyang Li
* @since 0.8
*/
public abstract class AbstractQueryCache extends AbstractPoolable implements QueryCache {
protected final ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock();
protected final Properties propNameIndexMap = new Properties<>();
protected long lastUpdatedTime = System.currentTimeMillis();
protected boolean isClosed = false;
protected AbstractQueryCache(long liveTime, long maxIdleTime) {
super(liveTime, maxIdleTime);
}
/**
* Lock.
*/
@Override
public void lock() {
rwLock.readLock().lock();
}
/**
* Unlock.
*/
@Override
public void unlock() {
rwLock.readLock().unlock();
}
/**
* Gets the prop index.
*
* @param propName
* @return
*/
@Override
public int getPropIndex(String propName) {
assertNotClosed();
return propNameIndexMap.getOrDefault(propName, -1);
}
/**
* Gets the cached prop names.
*
* @return
*/
@Override
public Collection getCachedPropNames() {
assertNotClosed();
lock();
try {
return (getDataGrid() == null) ? N. emptyList() : propNameIndexMap.keySet();
} finally {
unlock();
}
}
/**
* Checks if is cached result.
*
* @param propName
* @param range
* @return true, if is cached result
*/
@Override
public boolean isCachedResult(String propName, Cache.Range range) {
assertNotClosed();
lock();
try {
DataGrid
© 2015 - 2025 Weber Informatics LLC | Privacy Policy