-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[Collections] Use persistent cache for GitHub package metadata #3441
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
Conversation
@swift-ci please smoke test |
import TSCUtility | ||
|
||
/// SQLite backed persistent cache. | ||
public final class SQLiteBackedCache<Value: Codable>: Closable { |
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.
This is formerly SQLiteManifestCache
} | ||
} | ||
|
||
public func put(key: Key, value: Value, replace: Bool = false) throws { |
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.
Add option to replace or ignore
if let cache = self.cache { | ||
cache[reference] = (model, DispatchTime.now()) | ||
|
||
if cache.count > self.configuration.cacheSize { |
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.
With the max size feature in SQLite cache, we don't need to manually delete cache entries.
@@ -585,23 +584,23 @@ public final class ManifestLoader: ManifestLoaderProtocol { | |||
} | |||
|
|||
fileprivate func parseAndCacheManifest(key: ManifestCacheKey, diagnostics: DiagnosticsEngine?) -> ManifestParseResult { | |||
let cache = self.databaseCacheDir.map { cacheDir -> SQLiteManifestCache in | |||
let cache = self.databaseCacheDir.map { cacheDir -> SQLiteBackedCache<ManifestParseResult> in |
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.
This is the main change in this file. The rest is formatting / refactoring.
import TSCUtility | ||
import XCTest | ||
|
||
final class SQLiteBackedCacheTests: XCTestCase { |
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.
Copied from manifest cache tests.
@swift-ci please smoke test |
1 similar comment
@swift-ci please smoke test |
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.
Great 👍
throw error | ||
} | ||
self.diagnosticsEngine?.emit(.warning("truncating \(self.name) cache database since it reached max size of \(self.configuration.maxSizeInBytes ?? 0) bytes")) | ||
try self.executeStatement("DELETE FROM \(self.name);") { statement -> Void in |
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 future idea, we can evolve configuration.truncateWhenFull
to determine more fine grained rules
Motivation: Currently we use transient in-memory cache for storing GitHub package metadata. Modifications: - Add generic `SQLiteBackedCache` in Basics - Change `ManifestLoader` to use `SQLiteBackedCache` - Change `GitHubPackageMetadataProvider` to use `SQLiteBackedCache` - Adjust tests
@swift-ci please smoke test |
@swift-ci please smoke test macOS |
@swift-ci please smoke test macOS |
https://ci.swift.org/job/swift-package-manager-PR-macos-smoke-test/3140/console
|
@swift-ci please smoke test macOS |
…lang#3441) * [Collections] Use persistent cache for GitHub package metadata Motivation: Currently we use transient in-memory cache for storing GitHub package metadata. Modifications: - Add generic `SQLiteBackedCache` in Basics - Change `ManifestLoader` to use `SQLiteBackedCache` - Change `GitHubPackageMetadataProvider` to use `SQLiteBackedCache` - Adjust tests * Undo swiftformat changes * Fix CMake build * Rename name to tableName * Document 'tableName'
#3453) * [Collections] Use persistent cache for GitHub package metadata Motivation: Currently we use transient in-memory cache for storing GitHub package metadata. Modifications: - Add generic `SQLiteBackedCache` in Basics - Change `ManifestLoader` to use `SQLiteBackedCache` - Change `GitHubPackageMetadataProvider` to use `SQLiteBackedCache` - Adjust tests * Undo swiftformat changes * Fix CMake build * Rename name to tableName * Document 'tableName'
Motivation:
Currently we use transient in-memory cache for storing GitHub package metadata.
Modifications:
SQLiteBackedCache
in BasicsManifestLoader
to useSQLiteBackedCache
GitHubPackageMetadataProvider
to useSQLiteBackedCache