cancel
Showing results for 
Search instead for 
Did you mean: 

Use of singleton class possible in gateway?

VincentBloem
Participant
0 Kudos

Hi Experts,

I have a question,

We have a Fiori App where we use a valuehelp that shows some values when you open it. (0...1000 values)

There is also a searchfield provided on the valuehelp.

Each time we search the whole valueset must be loaded (because we have to do a filtering...)

Now, this takes a while each time you enter a character in the searchfield.

So we would use a singleton class to store the whole valuehelp dataset in it.

But, it looks like every time the service is called, the signleton class is initial.

Is it possible to use signleton classes in a gateway service?

SimoneMilesi
Active Contributor

Hi Vincent.
The fact is that each call to the backend (aka your class) creates a new LUW, so the class is always empty.

A solution I adopted for a similar issue is to load the data for search help at the beginning and store it into an UI5 object and then using the object without the call to the backend for all the operations.

I guess these aren't transactional data changing over and over, right?

Accepted Solutions (0)

Answers (1)

Answers (1)

SuhaSaha
Advisor
Advisor

The Singleton won't work because each backend access creates a new ABAP session & hence the singleton is no longer available. So it would create a new singleton instead.

If searching the value set is performance intensive, then you can serialize the singleton of the service once created & deserialize it for the next call. (cf. serialization of ABAP class instances).

Now, the question is how frequently do you want to refresh this "buffered" singleton? You might have to write a backend report to clear this buffer & schedule it as a job.

BR, Suhas

PS - Are you sure that the SAPUI5 framework doesn't have any mechanism to buffer such data?