0

I'm building an Android app that tracks Mutual Fund performance. The app allows you to create a portfolio to add your funds.

This being a mutual fund app (and not a stock app), it fetches the updated fund "price" (Net Asset Value Per Share) once a day and recomputes the portfolio (Current Value, Current Yield [+/-]). This "refresh" operation is expensive as it consumes data and a lot of CPU cycles.

The portfolio XML only contains user-inputted "static" data:

  • Funds in Portfolio
  • Investments in Funds (How much Shares were bought and when)

All computed "dynamic" data are not persisted anywhere. The rationale is that those data change under different circumstances (Fetched updated fund price, Added new Investments, etc).

As a result, when the user launches the app, the app reads the static data from the XML file, read the latest FUND PRICES (from DB or Web Service) and then proceeds recompute everything. This takes a substantial amount of time.

Question:

In the brave new world of Mobile Development where people expects snappy app responses, is it a new "best" practice to cache dynamic data instead of recomputing it everytime that it is needed?

Should I cache the dynamic data to make certain operations smooth and fast or should I just recompute everytime?

Thanks!

Ian
  • 5,625
  • 11
  • 57
  • 93

2 Answers2

1

I prefer not caching until I know it is necessary, because recomputing is less error-prone. So first I would do performance tuning by this technique on the time-consuming phase of execution. I think it's much easier to do performance tuning than to complexify the program by caching, especially when I'm not even positive it will help very much.

But after you do the performance tuning, and you can see that the recomputing still is the major time-taker, then yes, do caching.

Community
  • 1
  • 1
Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135
0

You should definitely cache data when it is necessary. You may consider using SoftReferences since they are retained as long as there is memory available and garbage collected before you are about to run out of memory. You may also consider that today's smart phones do have more resources than some personal computers.

fhsilva
  • 1,217
  • 1
  • 9
  • 17