@@ -109,7 +109,23 @@ static Function<Set<Database.Property>, IpDataLookup> getMaxmindLookup(final Dat
109109 };
110110 }
111111
112- static class AnonymousIp extends AbstractBase <AnonymousIpResponse , AnonymousIpResponse > {
112+ static class CacheableAnonymousIpResponse extends AnonymousIpResponse implements GeoIpCache .CacheableValue {
113+
114+ CacheableAnonymousIpResponse (AnonymousIpResponse response ) {
115+ super (
116+ response .getIpAddress (),
117+ response .isAnonymous (),
118+ response .isAnonymousVpn (),
119+ response .isHostingProvider (),
120+ response .isPublicProxy (),
121+ response .isResidentialProxy (),
122+ response .isTorExitNode (),
123+ response .getNetwork ()
124+ );
125+ }
126+ }
127+
128+ static class AnonymousIp extends AbstractBase <AnonymousIpResponse , CacheableAnonymousIpResponse > {
113129 AnonymousIp (final Set <Database .Property > properties ) {
114130 super (
115131 properties ,
@@ -119,12 +135,12 @@ static class AnonymousIp extends AbstractBase<AnonymousIpResponse, AnonymousIpRe
119135 }
120136
121137 @ Override
122- protected AnonymousIpResponse cacheableRecord (AnonymousIpResponse response ) {
123- return response ;
138+ protected CacheableAnonymousIpResponse cacheableRecord (AnonymousIpResponse response ) {
139+ return new CacheableAnonymousIpResponse ( response ) ;
124140 }
125141
126142 @ Override
127- protected Map <String , Object > transform (final AnonymousIpResponse response ) {
143+ protected Map <String , Object > transform (final CacheableAnonymousIpResponse response ) {
128144 boolean isHostingProvider = response .isHostingProvider ();
129145 boolean isTorExitNode = response .isTorExitNode ();
130146 boolean isAnonymousVpn = response .isAnonymousVpn ();
@@ -160,18 +176,30 @@ protected Map<String, Object> transform(final AnonymousIpResponse response) {
160176 }
161177 }
162178
163- static class Asn extends AbstractBase <AsnResponse , AsnResponse > {
179+ static class CacheableAsnResponse extends AsnResponse implements GeoIpCache .CacheableValue {
180+
181+ CacheableAsnResponse (AsnResponse response ) {
182+ super (
183+ response .getAutonomousSystemNumber (),
184+ response .getAutonomousSystemOrganization (),
185+ response .getIpAddress (),
186+ response .getNetwork ()
187+ );
188+ }
189+ }
190+
191+ static class Asn extends AbstractBase <AsnResponse , CacheableAsnResponse > {
164192 Asn (Set <Database .Property > properties ) {
165193 super (properties , AsnResponse .class , (response , ipAddress , network , locales ) -> new AsnResponse (response , ipAddress , network ));
166194 }
167195
168196 @ Override
169- protected AsnResponse cacheableRecord (AsnResponse response ) {
170- return response ;
197+ protected CacheableAsnResponse cacheableRecord (AsnResponse response ) {
198+ return new CacheableAsnResponse ( response ) ;
171199 }
172200
173201 @ Override
174- protected Map <String , Object > transform (final AsnResponse response ) {
202+ protected Map <String , Object > transform (final CacheableAsnResponse response ) {
175203 Long asn = response .getAutonomousSystemNumber ();
176204 String organizationName = response .getAutonomousSystemOrganization ();
177205 Network network = response .getNetwork ();
@@ -354,7 +382,14 @@ protected Map<String, Object> transform(final Result<CacheableCityResponse> resu
354382 }
355383 }
356384
357- static class ConnectionType extends AbstractBase <ConnectionTypeResponse , ConnectionTypeResponse > {
385+ static class CacheableConnectionTypeResponse extends ConnectionTypeResponse implements GeoIpCache .CacheableValue {
386+
387+ CacheableConnectionTypeResponse (ConnectionTypeResponse response ) {
388+ super (response .getConnectionType (), response .getIpAddress (), response .getNetwork ());
389+ }
390+ }
391+
392+ static class ConnectionType extends AbstractBase <ConnectionTypeResponse , CacheableConnectionTypeResponse > {
358393 ConnectionType (final Set <Database .Property > properties ) {
359394 super (
360395 properties ,
@@ -364,12 +399,12 @@ static class ConnectionType extends AbstractBase<ConnectionTypeResponse, Connect
364399 }
365400
366401 @ Override
367- protected ConnectionTypeResponse cacheableRecord (ConnectionTypeResponse response ) {
368- return response ;
402+ protected CacheableConnectionTypeResponse cacheableRecord (ConnectionTypeResponse response ) {
403+ return new CacheableConnectionTypeResponse ( response ) ;
369404 }
370405
371406 @ Override
372- protected Map <String , Object > transform (final ConnectionTypeResponse response ) {
407+ protected Map <String , Object > transform (final CacheableConnectionTypeResponse response ) {
373408 ConnectionTypeResponse .ConnectionType connectionType = response .getConnectionType ();
374409
375410 Map <String , Object > data = new HashMap <>();
@@ -479,7 +514,14 @@ protected Map<String, Object> transform(final Result<CacheableCountryResponse> r
479514 }
480515 }
481516
482- static class Domain extends AbstractBase <DomainResponse , DomainResponse > {
517+ static class CacheableDomainResponse extends DomainResponse implements GeoIpCache .CacheableValue {
518+
519+ CacheableDomainResponse (DomainResponse response ) {
520+ super (response .getDomain (), response .getIpAddress (), response .getNetwork ());
521+ }
522+ }
523+
524+ static class Domain extends AbstractBase <DomainResponse , CacheableDomainResponse > {
483525 Domain (final Set <Database .Property > properties ) {
484526 super (
485527 properties ,
@@ -489,12 +531,12 @@ static class Domain extends AbstractBase<DomainResponse, DomainResponse> {
489531 }
490532
491533 @ Override
492- protected DomainResponse cacheableRecord (DomainResponse response ) {
493- return response ;
534+ protected CacheableDomainResponse cacheableRecord (DomainResponse response ) {
535+ return new CacheableDomainResponse ( response ) ;
494536 }
495537
496538 @ Override
497- protected Map <String , Object > transform (final DomainResponse response ) {
539+ protected Map <String , Object > transform (final CacheableDomainResponse response ) {
498540 String domain = response .getDomain ();
499541
500542 Map <String , Object > data = new HashMap <>();
@@ -784,18 +826,25 @@ protected Map<String, Object> transform(final Result<CacheableEnterpriseResponse
784826 }
785827 }
786828
787- static class Isp extends AbstractBase <IspResponse , IspResponse > {
829+ static class CacheableIspResponse extends IspResponse implements GeoIpCache .CacheableValue {
830+
831+ CacheableIspResponse (IspResponse response ) {
832+ super (response , response .getIpAddress (), response .getNetwork ());
833+ }
834+ }
835+
836+ static class Isp extends AbstractBase <IspResponse , CacheableIspResponse > {
788837 Isp (final Set <Database .Property > properties ) {
789838 super (properties , IspResponse .class , (response , ipAddress , network , locales ) -> new IspResponse (response , ipAddress , network ));
790839 }
791840
792841 @ Override
793- protected IspResponse cacheableRecord (IspResponse response ) {
794- return response ;
842+ protected CacheableIspResponse cacheableRecord (IspResponse response ) {
843+ return new CacheableIspResponse ( response ) ;
795844 }
796845
797846 @ Override
798- protected Map <String , Object > transform (final IspResponse response ) {
847+ protected Map <String , Object > transform (final CacheableIspResponse response ) {
799848 String isp = response .getIsp ();
800849 String ispOrganization = response .getOrganization ();
801850 String mobileNetworkCode = response .getMobileNetworkCode ();
@@ -867,7 +916,9 @@ private interface ResponseBuilder<RESPONSE extends AbstractResponse> {
867916 *
868917 * @param <RESPONSE> the intermediate type of {@link AbstractResponse}
869918 */
870- private abstract static class AbstractBase <RESPONSE extends AbstractResponse , RECORD > implements IpDataLookup {
919+ private abstract static class AbstractBase <RESPONSE extends AbstractResponse , RECORD extends GeoIpCache .CacheableValue >
920+ implements
921+ IpDataLookup {
871922
872923 protected final Set <Database .Property > properties ;
873924 protected final Class <RESPONSE > clazz ;
0 commit comments