I'm frequently using a time-consuming method from a vendor library ResultObject complexMethod(ComplexObject obj)
and therefore I want to cache the results. The difficulty is that lots of fields in my ComplexObject are involved in the result but also lots of fields are not, so the solution is definitely not to put the ComplexObj as map key. I want to find an easy way to build a key that will include the exact necessary fields. I have come up with the quite tedious idea to create a new method with the minimal arguments and add the arguments until I'm getting the expected results :
public ResultObject complexMethod(String arg1, int arg2, double arg3, ..., String argN) {
ComplexObject obj = new ComplexObject();
obj.setField1(arg1);
...
obj.setFieldN(argN);
ResultObject result = ComplexClass.complexMethod(obj);
return result;
}
But this is not a satisfying solution for me because I want to know the exact fields that are used in the computation.
Is there a correct way to achieve this or any library which does the job ?
Aucun commentaire:
Enregistrer un commentaire