-
Notifications
You must be signed in to change notification settings - Fork 4
Db format changes and use CacheKey in more places #108
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
Changes from 25 commits
b3ef6b4
88bdae1
515a463
46b783b
0c17246
9aff3c9
ce594f1
8263ee2
ed1057e
ee20dca
2dd3697
4f6c58d
1bc2238
ec15cbd
001ec2a
cf891be
d4d8b9e
e261f1d
646ee02
5865784
7b3b11a
7d45d84
f0232f1
91b924c
073c4d1
21ecb03
db4d91d
3e7ecde
59f1296
9840218
0acb637
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
package com.apollographql.cache.normalized.api | ||
|
||
import com.apollographql.apollo.annotations.ApolloInternal | ||
import kotlin.jvm.JvmInline | ||
import kotlin.jvm.JvmStatic | ||
|
||
/** | ||
* A [CacheKey] identifies an object in the cache. | ||
* | ||
* @param key The key of the object in the cache. The key must be globally unique. | ||
*/ | ||
class CacheKey(val key: String) { | ||
|
||
@JvmInline | ||
value class CacheKey( | ||
martinbonnin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** | ||
* The key of the object in the cache. | ||
*/ | ||
val key: String, | ||
) { | ||
/** | ||
* Builds a [CacheKey] from a typename and a list of Strings. | ||
* | ||
|
@@ -31,15 +36,14 @@ class CacheKey(val key: String) { | |
*/ | ||
constructor(typename: String, vararg values: String) : this(typename, values.toList()) | ||
|
||
override fun hashCode() = key.hashCode() | ||
override fun equals(other: Any?): Boolean { | ||
return key == (other as? CacheKey)?.key | ||
fun keyToString(): String { | ||
return key | ||
martinbonnin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
override fun toString() = "CacheKey($key)" | ||
override fun toString() = "CacheKey(${keyToString()})" | ||
|
||
fun serialize(): String { | ||
return "$SERIALIZATION_TEMPLATE{$key}" | ||
return "$SERIALIZATION_TEMPLATE{${keyToString()}}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can probably remove all of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is actually used by the IJ Plugin, but yes honestly this doesn't need to be here. |
||
} | ||
|
||
companion object { | ||
|
@@ -71,3 +75,21 @@ class CacheKey(val key: String) { | |
} | ||
} | ||
} | ||
|
||
fun CacheKey.isRootKey(): Boolean { | ||
return this == CacheKey.rootKey() | ||
martinbonnin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
@ApolloInternal | ||
fun CacheKey.fieldKey(fieldName: String): String { | ||
martinbonnin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return "${keyToString()}.$fieldName" | ||
} | ||
|
||
@ApolloInternal | ||
fun CacheKey.append(vararg keys: String): CacheKey { | ||
martinbonnin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var cacheKey: CacheKey = this | ||
for (key in keys) { | ||
cacheKey = CacheKey("${cacheKey.key}.$key") | ||
} | ||
return cacheKey | ||
} |
Uh oh!
There was an error while loading. Please reload this page.