FINERACT-2234: add extra caches to frequent database queries during the interest recalculation

This commit is contained in:
budaidev
2025-04-28 14:51:11 +02:00
committed by Adam Saghy
parent efd17d5a3e
commit 6d3e19cf25
7 changed files with 382 additions and 10 deletions
@@ -20,6 +20,9 @@ package org.apache.fineract.organisation.monetary.domain;
import java.util.List;
import org.apache.fineract.organisation.monetary.data.CurrencyData;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
@@ -28,16 +31,61 @@ import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
@Repository
@CacheConfig(cacheNames = "currencies")
public interface ApplicationCurrencyRepository
extends JpaRepository<ApplicationCurrency, Long>, JpaSpecificationExecutor<ApplicationCurrency> {
String FIND_CURRENCY_DETAILS = "SELECT new org.apache.fineract.organisation.monetary.data.CurrencyData(ac.code, ac.name, ac.decimalPlaces, ac.inMultiplesOf, ac.displaySymbol, ac.nameCode) FROM ApplicationCurrency ac ";
@Cacheable(key = "'entity_' + #currencyCode")
ApplicationCurrency findOneByCode(String currencyCode);
@Cacheable(key = "'data_' + #currencyCode")
@Query(FIND_CURRENCY_DETAILS + " WHERE ac.code = :code")
CurrencyData findCurrencyDataByCode(@Param("code") String currencyCode);
@Cacheable
@Query(FIND_CURRENCY_DETAILS)
List<CurrencyData> findAllSorted(Sort sort);
/**
* Override save method with cache eviction
*/
@Override
@CacheEvict(allEntries = true)
<S extends ApplicationCurrency> S save(S entity);
/**
* Override saveAll method with cache eviction
*/
@Override
@CacheEvict(allEntries = true)
<S extends ApplicationCurrency> List<S> saveAll(Iterable<S> entities);
/**
* Override delete methods with cache eviction
*/
@Override
@CacheEvict(allEntries = true)
void delete(ApplicationCurrency entity);
@Override
@CacheEvict(allEntries = true)
void deleteAll();
@Override
@CacheEvict(allEntries = true)
void deleteAll(Iterable<? extends ApplicationCurrency> entities);
@Override
@CacheEvict(allEntries = true)
void deleteById(Long id);
@Override
@CacheEvict(allEntries = true)
void deleteAllById(Iterable<? extends Long> ids);
@Override
@CacheEvict(allEntries = true)
<S extends ApplicationCurrency> S saveAndFlush(S entity);
}