| 
 | 1 | +/*  | 
 | 2 | + * Copyright 2024 the original author or authors.  | 
 | 3 | + *  | 
 | 4 | + * Licensed under the Apache License, Version 2.0 (the "License");  | 
 | 5 | + * you may not use this file except in compliance with the License.  | 
 | 6 | + * You may obtain a copy of the License at  | 
 | 7 | + *  | 
 | 8 | + *      https://www.apache.org/licenses/LICENSE-2.0  | 
 | 9 | + *  | 
 | 10 | + * Unless required by applicable law or agreed to in writing, software  | 
 | 11 | + * distributed under the License is distributed on an "AS IS" BASIS,  | 
 | 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | 
 | 13 | + * See the License for the specific language governing permissions and  | 
 | 14 | + * limitations under the License.  | 
 | 15 | + */  | 
 | 16 | +package org.springframework.data.repository.query;  | 
 | 17 | + | 
 | 18 | +import org.springframework.data.expression.ValueExpression;  | 
 | 19 | +import org.springframework.data.expression.ValueExpressionParser;  | 
 | 20 | +import org.springframework.expression.ParseException;  | 
 | 21 | +import org.springframework.util.ConcurrentLruCache;  | 
 | 22 | + | 
 | 23 | +/**  | 
 | 24 | + * Caching variant of {@link ValueExpressionSupportHolder}.  | 
 | 25 | + *  | 
 | 26 | + * @author Mark Paluch  | 
 | 27 | + */  | 
 | 28 | +public class CachingValueExpressionSupportHolder extends ValueExpressionSupportHolder {  | 
 | 29 | + | 
 | 30 | +	private final ConcurrentLruCache<String, ValueExpression> expressionCache;  | 
 | 31 | + | 
 | 32 | +	public CachingValueExpressionSupportHolder(ValueExpressionSupportHolder supportHolder) {  | 
 | 33 | +		super(supportHolder);  | 
 | 34 | +		this.expressionCache = new ConcurrentLruCache<>(256, supportHolder.getValueExpressionParser()::parse);  | 
 | 35 | +	}  | 
 | 36 | + | 
 | 37 | +	public CachingValueExpressionSupportHolder(QueryMethodValueEvaluationContextProviderFactory providerFactory,  | 
 | 38 | +			ValueExpressionParser valueExpressionParser) {  | 
 | 39 | +		super(providerFactory, valueExpressionParser);  | 
 | 40 | +		this.expressionCache = new ConcurrentLruCache<>(256, valueExpressionParser::parse);  | 
 | 41 | +	}  | 
 | 42 | + | 
 | 43 | +	@Override  | 
 | 44 | +	public ValueExpressionParser getValueExpressionParser() {  | 
 | 45 | +		return this;  | 
 | 46 | +	}  | 
 | 47 | + | 
 | 48 | +	@Override  | 
 | 49 | +	public ValueExpression parse(String expressionString) throws ParseException {  | 
 | 50 | +		return expressionCache.get(expressionString);  | 
 | 51 | +	}  | 
 | 52 | +}  | 
0 commit comments