Caching implementation for demonstration purposes

This commit is contained in:
2025-09-07 23:58:00 +05:00
parent 77b8602a0a
commit 411c90f6c6
3 changed files with 47 additions and 7 deletions

View File

@ -0,0 +1,17 @@
package com.backend.vue.bff.service.config;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableCaching
public class CacheConfig {
@Bean
public CacheManager cacheManager() {
return new ConcurrentMapCacheManager("kodikId", "kodikSearch");
}
}

View File

@ -2,24 +2,22 @@ package com.backend.vue.bff.service.controller;
import java.io.IOException; import java.io.IOException;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.backend.search.kodik.api.SearchControllerApi; import com.backend.vue.bff.service.service.KodikService;
@RestController @RestController
public class TestController { public class TestController {
private final ObjectProvider<SearchControllerApi> controllerApiFactory; private final KodikService kodikService;
public TestController(ObjectProvider<SearchControllerApi> controllerApiFactory) { public TestController(KodikService kodikService) {
this.controllerApiFactory = controllerApiFactory; this.kodikService = kodikService;
} }
@GetMapping("/test") @GetMapping("/test")
public String test(@RequestParam(name = "title") String title) throws IOException { public String test(@RequestParam(name = "title") String title) throws IOException {
SearchControllerApi api = controllerApiFactory.getObject(); return Integer.toString(kodikService.search(title).getResults().size());
return Integer.toString(api.search(title).execute().body().getResults().size());
} }
} }

View File

@ -0,0 +1,25 @@
package com.backend.vue.bff.service.service;
import java.io.IOException;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import com.backend.search.kodik.api.SearchControllerApi;
import com.backend.search.kodik.model.KodikResponse;
@Service
public class KodikService {
private final ObjectProvider<SearchControllerApi> controllerApiFactory;
public KodikService(ObjectProvider<SearchControllerApi> controllerApiFactory) {
this.controllerApiFactory = controllerApiFactory;
}
@Cacheable("kodikSearch")
public KodikResponse search(String title) throws BeansException, IOException {
return controllerApiFactory.getObject().search(title).execute().body();
}
}