Search code examples
c++icu

How does the C++ ICU library decide which Calendar objects to cache?


We use the C++ ICU library's Calendar::createInstance(...) function to get a pointer to a Calendar object.

Would multiple identical calls to Calendar::createInstance(...) with the same arguments result in

a. ICU creating a brand new Calendar object each time or

b. Would the library use it's internal cache and return the existing instance of this Calendar for the second and subsequent calls?

The API does not seem to offer specific caching details besides mentioning that the library may elect to perform caching through these internal only functions:

a. Calendar::registerFactory(...) and

b. Calendar::makeInstance(...)

Could someone please shed light on how Calendar objects are cached by the C++ ICU library?


Solution

  • You can see the source code here: http://source.icu-project.org/repos/icu/icu/tags/release-58-1/source/i18n/calendar.cpp

    It ultimately uses UnifiedCache::_get() which is here: http://source.icu-project.org/repos/icu/icu/tags/release-58-1/source/common/unifiedcache.cpp