-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor cache policies #20
Conversation
TODO:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. I've added a few comments
Sources/Transifex/Cache.swift
Outdated
///``` | ||
/// | Key | Cache | New | All | Using Translated Only | Untranslated Only | | ||
/// |-----|-------|------|------|-----------------------|-------------------| | ||
/// | 1 | 1 | None | None | 1 | 1 | | ||
/// | 2 | 1 | 2 | 2 | 2 | 1 | | ||
/// | 3 | 1 | "" | "" | 1 | 1 | | ||
/// | 4 | "" | None | None | "" | "" | | ||
/// | 5 | "" | 2 | 2 | 2 | 2 | | ||
/// | 6 | None | 2 | 2 | 2 | 2 | | ||
///``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change this to:
| Key || Cache | New || Overide All | Using Translated Only | Untranslated Only |
|-----||-------|------||--------------|-----------------------|-------------------|
| a || "a" | - || - | "a" | "a" |
| b || "b" | "B" || "B" | "B" | "b" |
| c || "c" | "" || "" | "c" | "c" |
| d || "" | - || - | "" | "" |
| e || "" | "E" || "E" | "E" | "E" |
| f || - | "F" || "F" | "F" | "F" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added!
Sources/Transifex/Cache.swift
Outdated
/// | 4 | "" | None | None | "" | "" | | ||
/// | 5 | "" | 2 | 2 | 2 | 2 | | ||
/// | 6 | None | 2 | 2 | 2 | 2 | | ||
///``` | ||
@objc | ||
public enum TXCacheOverridePolicy : Int { | ||
/// All of the cache entries are replaced with the new translations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the following would be more clear, what do you think?:
/// Discards the existing cache entries completely and populates the cache with the new entries, even if they contain empty translations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup that's better, I replaced it.
Sources/Transifex/Cache.swift
Outdated
/// New translations update the cache (updating existing entries or adding new ones) and any cached | ||
/// translations that aren't updated are left as-is. | ||
/// If a cached translation exists and it's not an empty string and the value for the new translation is an | ||
/// empty string, then the cached translation is left as -is. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about simplifying it:
Updates the existing cache with the new entries that have a non-empty translation, ignoring the rest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced.
Sources/Transifex/Cache.swift
Outdated
/// Only the translations that don't exist in the cache or cached translations that contain empty strings | ||
/// are updated / added, otherwise they are left as-is. | ||
/// If a cached translation exists and it's not an empty string and the value for the new translation is an | ||
/// empty string, then the cached translation is left as -is. | ||
case overrideUntranslatedOnly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed offline, let's remove overrideUntranslatedOnly
completely, as it doesn't seem to cover a plausible customer flow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
@@ -330,7 +330,7 @@ final class TransifexTests: XCTestCase { | |||
|
|||
XCTAssertNil(cache.get(key: "key1", localeCode: "en")) | |||
XCTAssertNotNil(cache.get(key: "key2", localeCode: "en")) | |||
XCTAssertNil(cache.get(key: "key3", localeCode: "en")) | |||
XCTAssertNotNil(cache.get(key: "key3", localeCode: "en")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should update all tests to include all cases described in the nice table you created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have pushed a commit that replaces the existing policy unit tests with two tests that use the provided table.
Sources/Transifex/Cache.swift
Outdated
/// - groupIdentifier: The group identifier of the app, if the app makes use of the app groups | ||
/// entitlement. Defaults to nil. | ||
@objc | ||
public init(overridePolicy: TXCacheOverridePolicy = .overrideAll, | ||
public init(overridePolicy: TXCacheOverridePolicy = .overrideUsingTranslatedOnly, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed offline, let's use .overrideAll
as the default policy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched back to .overrideAll
policy here.
@dbendilas I have just pushed a new commit that covers the points raised during review. I can leave it as WIP until cache implementation has been also finalized in the Android version. |
40943d3
to
3e465f2
Compare
5fb3186
to
1f326e0
Compare
1f326e0
to
9f9d5e8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
@dbendilas I just pushed a final commit replacing the 'override' term with 'update' where applicable, to reflect the change of the enum. If everything looks OK from your side, let's approve and merge this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Please squash and I'll approve
Refactors cache policies based on the latest discussion between @dbendilas and @Petrakeas. The empty translations (`""`) are now added in the cache (depending on the policy) and they are not filtered out. A helpful cheat-sheet table has been added in the documentation of the `TXCacheOverridePolicy` and the policy documentation has been also updated. The cache now defaults to the `.overrideUsingTranslatedOnly` instead of the `.overrideAll` policy, if no policy is specified by the developer. If a cache entry is found to contain an empty string during rendering, the logic falls back to the missing policy. The documentation of the `TXDiskCacheProvider` has been updated to declare that it initializes the disk cache provider synchronously. * Improves policy unit tests by using the table provided in the documentation to initialize a memory cache and a set of new translations. * Adds a unit test that tests whether the read only cache (`TXReadOnlyCacheDecorator`) is immutable. * Refactors `TXStandardCache` to use a static method that constructs and returns the `TXCache` object instead of using the decorator pattern. Updates the default standard cache usage in the `NativeCore` class and the README instructions. * Renames override policy enum to update policy and updates the values to match the ones used by the Java SDK. * Replaces occurrences of the 'override' term (relating to the override policy) with the 'update' term, to match the rename of the override policy enum. * Updates CHANGELOG, bumps version
eb561e2
to
a3e162a
Compare
Done! |
Refactors cache policies based on the latest discussion between
@dbendilas and @Petrakeas.
The empty translations (
""
) are now added in the cache (depending onthe policy) and they are not filtered out.
A helpful cheat-sheet table has been added in the documentation of the
TXCacheOverridePolicy
and the policy documentation has been alsoupdated.
The cache now defaults to the
.overrideUsingTranslatedOnly
instead ofthe
.overrideAll
policy, if no policy is specified by the developer.If a cache entry is found to contain an empty string during rendering,
the logic falls back to the missing policy.
The documentation of the
TXDiskCacheProvider
has been updated todeclare that it initializes the disk cache provider synchronously.