2
0

AppsCasDetailsService.java 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
  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. * http://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.maxkey.persistence.service;
  17. import java.util.concurrent.TimeUnit;
  18. import org.apache.mybatis.jpa.persistence.JpaBaseService;
  19. import org.maxkey.entity.apps.AppsCasDetails;
  20. import org.maxkey.persistence.mapper.AppsCasDetailsMapper;
  21. import org.springframework.stereotype.Repository;
  22. import com.github.benmanes.caffeine.cache.Cache;
  23. import com.github.benmanes.caffeine.cache.Caffeine;
  24. @Repository
  25. public class AppsCasDetailsService extends JpaBaseService<AppsCasDetails>{
  26. protected final static Cache<String, AppsCasDetails> detailsCache =
  27. Caffeine.newBuilder()
  28. .expireAfterWrite(30, TimeUnit.MINUTES)
  29. .maximumSize(200000)
  30. .build();
  31. public AppsCasDetailsService() {
  32. super(AppsCasDetailsMapper.class);
  33. }
  34. /* (non-Javadoc)
  35. * @see com.connsec.db.service.BaseService#getMapper()
  36. */
  37. @Override
  38. public AppsCasDetailsMapper getMapper() {
  39. return (AppsCasDetailsMapper)super.getMapper();
  40. }
  41. public AppsCasDetails getAppDetails(String id , boolean cached) {
  42. AppsCasDetails details = null;
  43. if(cached) {
  44. details = detailsCache.getIfPresent(id);
  45. if(details == null) {
  46. details = getMapper().getAppDetails(id);
  47. detailsCache.put(id, details);
  48. }
  49. }else {
  50. details = getMapper().getAppDetails(id);
  51. }
  52. return details;
  53. }
  54. }