1818package org .minbox .framework .api .boot .plugin .resource .load .context ;
1919
2020import org .minbox .framework .api .boot .plugin .resource .load .annotation .ResourceField ;
21- import org .minbox .framework .api .boot .plugin .resource .load .model .ResourcePushField ;
2221import org .slf4j .Logger ;
2322import org .slf4j .LoggerFactory ;
24- import org .springframework .util .ObjectUtils ;
2523
24+ import java .lang .reflect .Field ;
2625import java .lang .reflect .Method ;
27- import java .util .HashMap ;
2826import java .util .List ;
29- import java .util .Map ;
3027import java .util .concurrent .ConcurrentHashMap ;
3128import java .util .concurrent .ConcurrentMap ;
3229
@@ -54,48 +51,34 @@ public class ApiBootResourceContext {
5451 private static ConcurrentMap <String , List <ResourceField >> RESOURCE_FIELD_ANNOTATIONS = new ConcurrentHashMap ();
5552 /**
5653 * key -> method name
57- * child map key -> resource field name
58- * child map value -> resource field instance
54+ * value -> field instance
5955 */
60- private static ConcurrentMap <String , Map < String , ResourcePushField > > RESOURCE_FIELDS = new ConcurrentHashMap ();
56+ private static ConcurrentMap <String , Field > RESOURCE_FIELDS = new ConcurrentHashMap ();
6157
6258 /**
6359 * get push field from cache
6460 *
65- * @param method method instance
66- * @param fieldName 字段名称
67- * @return ResourceField list
61+ * @param declaredFieldClassName declared field class name
62+ * @param fieldName field name
63+ * @return Field
6864 */
69- public static ResourcePushField getPushFieldFromCache (Method method , String fieldName ) {
70- String methodName = formatterMethodName ( method );
71- logger .debug ("Cache method [{}] push field from memory" , methodName );
72- Map < String , ResourcePushField > resourcePushFieldMap = ApiBootResourceContext .RESOURCE_FIELDS .get (methodName );
73- return ObjectUtils . isEmpty ( resourcePushFieldMap ) ? null : resourcePushFieldMap . get ( fieldName ) ;
65+ public static Field getPushFieldFromCache (String declaredFieldClassName , String fieldName ) {
66+ String cacheKey = formatterCacheKey ( declaredFieldClassName , fieldName );
67+ logger .debug ("Cache method [{}] push field from memory" , cacheKey );
68+ Field field = ApiBootResourceContext .RESOURCE_FIELDS .get (cacheKey );
69+ return field ;
7470 }
7571
7672 /**
7773 * set push field to cache
7874 *
79- * @param method method instance
80- * @param resourcePushField push fields
75+ * @param declaredFieldClassName declared field class name
76+ * @param field push field
8177 */
82- public static void setPushFieldToCache (Method method , String fieldName , ResourcePushField resourcePushField ) {
83- String methodName = formatterMethodName (method );
84- logger .debug ("Cache method [{}] push field to memory" , methodName );
85- Map <String , ResourcePushField > resourcePushFieldMap = ApiBootResourceContext .RESOURCE_FIELDS .get (methodName );
86- // new map
87- if (ObjectUtils .isEmpty (resourcePushFieldMap )) {
88- resourcePushFieldMap = new HashMap (1 ) {
89- {
90- put (fieldName , resourcePushField );
91- }
92- };
93- }
94- //already have map
95- else {
96- resourcePushFieldMap .put (fieldName , resourcePushField );
97- }
98- ApiBootResourceContext .RESOURCE_FIELDS .put (methodName , resourcePushFieldMap );
78+ public static void setPushFieldToCache (String declaredFieldClassName , String fieldName , Field field ) {
79+ String cacheKey = formatterCacheKey (declaredFieldClassName , fieldName );
80+ logger .debug ("Cache method [{}] push field to memory" , cacheKey );
81+ ApiBootResourceContext .RESOURCE_FIELDS .put (cacheKey , field );
9982 }
10083
10184 /**
@@ -122,6 +105,18 @@ public static void setResourceFieldToCache(Method method, List<ResourceField> re
122105 ApiBootResourceContext .RESOURCE_FIELD_ANNOTATIONS .put (methodName , resourceFields );
123106 }
124107
108+ /**
109+ * formatter field cache key
110+ *
111+ * @param declaredFieldClassName declared file class name
112+ * @param fieldName field name
113+ * @return
114+ */
115+ private static String formatterCacheKey (String declaredFieldClassName , String fieldName ) {
116+ String expression = "%s.%s" ;
117+ return String .format (expression , declaredFieldClassName , fieldName );
118+ }
119+
125120 /**
126121 * formatter method name
127122 *
0 commit comments