Caching implementation for demonstration purposes
This commit is contained in:
@ -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");
|
||||
}
|
||||
}
|
@ -2,24 +2,22 @@ package com.backend.vue.bff.service.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.backend.search.kodik.api.SearchControllerApi;
|
||||
import com.backend.vue.bff.service.service.KodikService;
|
||||
|
||||
@RestController
|
||||
public class TestController {
|
||||
private final ObjectProvider<SearchControllerApi> controllerApiFactory;
|
||||
private final KodikService kodikService;
|
||||
|
||||
public TestController(ObjectProvider<SearchControllerApi> controllerApiFactory) {
|
||||
this.controllerApiFactory = controllerApiFactory;
|
||||
public TestController(KodikService kodikService) {
|
||||
this.kodikService = kodikService;
|
||||
}
|
||||
|
||||
@GetMapping("/test")
|
||||
public String test(@RequestParam(name = "title") String title) throws IOException {
|
||||
SearchControllerApi api = controllerApiFactory.getObject();
|
||||
return Integer.toString(api.search(title).execute().body().getResults().size());
|
||||
return Integer.toString(kodikService.search(title).getResults().size());
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user