Interface CacheEntryRepository
- All Superinterfaces:
org.springframework.data.repository.CrudRepository<CacheEntry, Long>, org.springframework.data.jpa.repository.JpaRepository<CacheEntry, Long>, org.springframework.data.repository.ListCrudRepository<CacheEntry, Long>, org.springframework.data.repository.ListPagingAndSortingRepository<CacheEntry, Long>, org.springframework.data.repository.PagingAndSortingRepository<CacheEntry, Long>, org.springframework.data.repository.query.QueryByExampleExecutor<CacheEntry>, org.springframework.data.repository.Repository<CacheEntry, Long>
@Repository
public interface CacheEntryRepository
extends org.springframework.data.jpa.repository.JpaRepository<CacheEntry, Long>
Spring Data JPA repository for cache entry persistence.
All native write-through queries use PostgreSQL syntax. Local H2 tests run in PostgreSQL compatibility mode so production SQL is exercised before release.
-
Method Summary
Modifier and TypeMethodDescriptionlongcountByMapName(String mapName) voiddeleteByMapName(String mapName) voiddeleteByMapNameAndCacheKey(String mapName, String cacheKey) booleanexistsByMapNameAndCacheKey(String mapName, String cacheKey) org.springframework.data.domain.Page<CacheEntry> findByMapName(String mapName, org.springframework.data.domain.Pageable pageable) findByMapNameAndCacheKey(String mapName, String cacheKey) org.springframework.data.domain.Page<String> findKeysByMapName(String mapName, org.springframework.data.domain.Pageable pageable) voidupsert(String mapName, String cacheKey, @Nullable String cacheValue, @Nullable String valueType, @Nullable String nodeId) Upsert a cache entry in a single PostgreSQL-compatible statement.Methods inherited from interface org.springframework.data.repository.CrudRepository
count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, saveMethods inherited from interface org.springframework.data.jpa.repository.JpaRepository
deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlushMethods inherited from interface org.springframework.data.repository.ListCrudRepository
findAll, findAllById, saveAllMethods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.PagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor
count, exists, findAll, findBy, findOne
-
Method Details
-
findByMapNameAndCacheKey
-
findByMapName
org.springframework.data.domain.Page<CacheEntry> findByMapName(String mapName, org.springframework.data.domain.Pageable pageable) -
existsByMapNameAndCacheKey
-
deleteByMapNameAndCacheKey
-
deleteByMapName
@Transactional @Modifying(clearAutomatically=true, flushAutomatically=true) void deleteByMapName(String mapName) -
countByMapName
-
findKeysByMapName
-
upsert
@Transactional @Modifying @Query(value="MERGE INTO CACHE_ENTRIES AS t\nUSING (VALUES (:mapName, :cacheKey, :cacheValue, :valueType, :nodeId))\n AS s(MAP_NAME, CACHE_KEY, CACHE_VALUE, VALUE_TYPE, NODE_ID)\nON (t.MAP_NAME = s.MAP_NAME AND t.CACHE_KEY = s.CACHE_KEY)\nWHEN MATCHED THEN UPDATE SET\n CACHE_VALUE = s.CACHE_VALUE,\n VALUE_TYPE = s.VALUE_TYPE,\n NODE_ID = s.NODE_ID,\n UPDATED_AT = CURRENT_TIMESTAMP,\n VERSION_NUM = COALESCE(t.VERSION_NUM, 0) + 1\nWHEN NOT MATCHED THEN INSERT\n (MAP_NAME, CACHE_KEY, CACHE_VALUE, VALUE_TYPE, NODE_ID, CREATED_AT, UPDATED_AT, VERSION_NUM)\n VALUES\n (s.MAP_NAME, s.CACHE_KEY, s.CACHE_VALUE, s.VALUE_TYPE, s.NODE_ID,\n CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 0)\n", nativeQuery=true) void upsert(@Param("mapName") String mapName, @Param("cacheKey") String cacheKey, @Param("cacheValue") @Nullable String cacheValue, @Param("valueType") @Nullable String valueType, @Param("nodeId") @Nullable String nodeId) Upsert a cache entry in a single PostgreSQL-compatible statement. Uses the unique index on (mapName, cacheKey) to decide INSERT vs UPDATE.Note: VERSION_NUM is managed manually in this native query, not via JPA @Version. Do not mix with repository.save() — all writes should go through upsert() for consistency.
flushAutomatically / clearAutomatically are intentionally off: the statement is a single native MERGE that never depends on the persistence context or detaches entities the caller might still be using. Leaving them on makes every hot PUT pay a full flush + context clear.
-