Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Get FormatCache after Format-ing

Discussion in 'Localization Tools' started by Kerber996, Jun 8, 2021.

  1. Kerber996

    Kerber996

    Joined:
    Nov 9, 2016
    Posts:
    23
    Is there a way to generate a FormatCache after formating a string, or is there another way of getting a FormatCache? Maybe a global cache?

    I have found methods that take FormatCache in, and use it, like in SmartFormater, but none that generate it. I have also looked into FormatCachePool, but I don't use Format, I use strings with SmartFormater.

    Thanks in advance :D
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,876
    Hi,
    The methods that take a FormatCache in will generate it for you when the value is null, they take a ref FormatCache value so can create a new instance if it is null.
    If you are getting localized values then we do keep a FormatCache in the StringTableEntry
    The caches are not global, they are on a per StringTableEntry basis so if the entries happen to have the exact same value they will need to generate 2 caches.
     
    Kerber996 likes this.
  3. Kerber996

    Kerber996

    Joined:
    Nov 9, 2016
    Posts:
    23
    Awesome, thanks so much Karl <3
     
    karl_jones likes this.
  4. Kerber996

    Kerber996

    Joined:
    Nov 9, 2016
    Posts:
    23
    I have not been able to get a cache value.

    I used Smart.Default.FormatWithCache, gave him a null Cache which he does initiate, passed him a format ("Test format {Format}"), and in the args list I put a object which has a "Format" string property (didn't exactly use this object but it's a good representation), and I'm not getting anything in the cache. I also tried using direct args for a " Test format {0}" format, and nothing.

    Am I using this wrong and expecting something that the Cache isn't supposed to do, or did I miss something in the setup?

    I'm trying to get a cached value like ["Format", returnedObject], because the values from the Reflection source vary by time, and I want to cache the returns for a given *time.
     
  5. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,876
    Ah yes the cache is just for parsing, not for the formatting. We dont cache the results, it would be hard to do when dealing with dynamic arguments as we would first need to go through the arguments and check if they have changed or not and that would require doing most of the formatting process. The best thing to do would be to cache the results yourself as you have a better understanding of when an argument will have changed or not.
     
    Kerber996 likes this.