Move byte store to package:analyzer

Change-Id: I1fc41cc0b2e2848565a5411d0512a4ca086ab659
Reviewed-on: https://dart-review.googlesource.com/c/77761
Commit-Queue: Peter von der Ahé <ahe@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Auto-Submit: Peter von der Ahé <ahe@google.com>
diff --git a/pkg/analysis_server/lib/src/analysis_server.dart b/pkg/analysis_server/lib/src/analysis_server.dart
index 38cc3ad..bdd5194 100644
--- a/pkg/analysis_server/lib/src/analysis_server.dart
+++ b/pkg/analysis_server/lib/src/analysis_server.dart
@@ -68,7 +68,9 @@
 import 'package:analyzer/src/util/glob.dart';
 import 'package:analyzer_plugin/protocol/protocol_common.dart' hide Element;
 import 'package:analyzer_plugin/src/utilities/navigation/navigation.dart';
-import 'package:front_end/src/api_prototype/byte_store.dart';
+import 'package:analyzer/src/dart/analysis/byte_store.dart';
+import 'package:analyzer/src/dart/analysis/file_byte_store.dart'
+    show EvictingFileByteStore;
 import 'package:analyzer/src/dart/analysis/performance_logger.dart';
 import 'package:telemetry/crash_reporting.dart';
 import 'package:telemetry/telemetry.dart' as telemetry;
diff --git a/pkg/analysis_server/test/abstract_context.dart b/pkg/analysis_server/test/abstract_context.dart
index 95ca1a7..ecbbbb32 100644
--- a/pkg/analysis_server/test/abstract_context.dart
+++ b/pkg/analysis_server/test/abstract_context.dart
@@ -20,7 +20,7 @@
 import 'package:analyzer/src/generated/source_io.dart';
 import 'package:analyzer/src/source/package_map_resolver.dart';
 import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
-import 'package:front_end/src/api_prototype/byte_store.dart';
+import 'package:analyzer/src/dart/analysis/byte_store.dart';
 import 'package:analyzer/src/dart/analysis/performance_logger.dart';
 
 import 'mock_sdk.dart';
diff --git a/pkg/analysis_server/test/context_manager_test.dart b/pkg/analysis_server/test/context_manager_test.dart
index 8d5659e..a2911fa 100644
--- a/pkg/analysis_server/test/context_manager_test.dart
+++ b/pkg/analysis_server/test/context_manager_test.dart
@@ -24,7 +24,7 @@
 import 'package:analyzer/src/summary/summary_file_builder.dart';
 import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
 import 'package:analyzer/src/util/glob.dart';
-import 'package:front_end/src/api_prototype/byte_store.dart';
+import 'package:analyzer/src/dart/analysis/byte_store.dart';
 import 'package:analyzer/src/dart/analysis/performance_logger.dart';
 import 'package:linter/src/rules.dart';
 import 'package:linter/src/rules/avoid_as.dart';
diff --git a/pkg/analysis_server/test/services/search/search_engine_test.dart b/pkg/analysis_server/test/services/search/search_engine_test.dart
index b0f0dde..009e5fc 100644
--- a/pkg/analysis_server/test/services/search/search_engine_test.dart
+++ b/pkg/analysis_server/test/services/search/search_engine_test.dart
@@ -15,7 +15,7 @@
 import 'package:analyzer/src/generated/source.dart';
 import 'package:analyzer/src/source/package_map_resolver.dart';
 import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
-import 'package:front_end/src/api_prototype/byte_store.dart';
+import 'package:analyzer/src/dart/analysis/byte_store.dart';
 import 'package:analyzer/src/dart/analysis/performance_logger.dart';
 import 'package:test/test.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
diff --git a/pkg/analysis_server/test/src/plugin/plugin_watcher_test.dart b/pkg/analysis_server/test/src/plugin/plugin_watcher_test.dart
index 69c8408..058ee15 100644
--- a/pkg/analysis_server/test/src/plugin/plugin_watcher_test.dart
+++ b/pkg/analysis_server/test/src/plugin/plugin_watcher_test.dart
@@ -18,7 +18,7 @@
 import 'package:analyzer/src/generated/source.dart';
 import 'package:analyzer/src/source/package_map_resolver.dart';
 import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
-import 'package:front_end/src/api_prototype/byte_store.dart';
+import 'package:analyzer/src/dart/analysis/byte_store.dart';
 import 'package:analyzer/src/dart/analysis/performance_logger.dart';
 import 'package:path/path.dart' as path;
 import 'package:test/test.dart';
diff --git a/pkg/analyzer/lib/src/context/builder.dart b/pkg/analyzer/lib/src/context/builder.dart
index 8315664..8c7104e 100644
--- a/pkg/analyzer/lib/src/context/builder.dart
+++ b/pkg/analyzer/lib/src/context/builder.dart
@@ -34,7 +34,7 @@
 import 'package:analyzer/src/task/options.dart';
 import 'package:analyzer/src/util/uri.dart';
 import 'package:args/args.dart';
-import 'package:front_end/src/api_prototype/byte_store.dart';
+import 'package:analyzer/src/dart/analysis/byte_store.dart';
 import 'package:analyzer/src/dart/analysis/performance_logger.dart';
 import 'package:package_config/packages.dart';
 import 'package:package_config/packages_file.dart';
diff --git a/pkg/analyzer/lib/src/dart/analysis/byte_store.dart b/pkg/analyzer/lib/src/dart/analysis/byte_store.dart
index ba051918..80f7b32 100644
--- a/pkg/analyzer/lib/src/dart/analysis/byte_store.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/byte_store.dart
@@ -1,9 +1,80 @@
-// Copyright (c) 2017, the Dart project authors.  Please see the AUTHORS file
+// Copyright (c) 2015, the Dart project authors.  Please see the AUTHORS file
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// This library re-exports the parts of front_end's byte_store.dart whose API is
-// stable enough to be relied upon by clients.
+import 'cache.dart';
 
-export 'package:front_end/src/api_prototype/byte_store.dart'
-    show ByteStore, MemoryByteStore, MemoryCachingByteStore;
+/**
+ * Store of bytes associated with string keys.
+ *
+ * Each key must be not longer than 100 characters and consist of only `[a-z]`,
+ * `[0-9]`, `.` and `_` characters. The key cannot be an empty string, the
+ * literal `.`, or contain the sequence `..`.
+ *
+ * Note that associations are not guaranteed to be persistent. The value
+ * associated with a key can change or become `null` at any point in time.
+ *
+ * TODO(scheglov) Research using asynchronous API.
+ */
+abstract class ByteStore {
+  /**
+   * Return the bytes associated with the given [key].
+   * Return `null` if the association does not exist.
+   */
+  List<int> get(String key);
+
+  /**
+   * Associate the given [bytes] with the [key].
+   */
+  void put(String key, List<int> bytes);
+}
+
+/**
+ * [ByteStore] which stores data only in memory.
+ */
+class MemoryByteStore implements ByteStore {
+  final Map<String, List<int>> _map = {};
+
+  @override
+  List<int> get(String key) {
+    return _map[key];
+  }
+
+  @override
+  void put(String key, List<int> bytes) {
+    _map[key] = bytes;
+  }
+}
+
+/**
+ * A wrapper around [ByteStore] which adds an in-memory LRU cache to it.
+ */
+class MemoryCachingByteStore implements ByteStore {
+  final ByteStore _store;
+  final Cache<String, List<int>> _cache;
+
+  MemoryCachingByteStore(this._store, int maxSizeBytes)
+      : _cache = new Cache<String, List<int>>(maxSizeBytes, (v) => v.length);
+
+  @override
+  List<int> get(String key) {
+    return _cache.get(key, () => _store.get(key));
+  }
+
+  @override
+  void put(String key, List<int> bytes) {
+    _store.put(key, bytes);
+    _cache.put(key, bytes);
+  }
+}
+
+/**
+ * [ByteStore] which does not store any data.
+ */
+class NullByteStore implements ByteStore {
+  @override
+  List<int> get(String key) => null;
+
+  @override
+  void put(String key, List<int> bytes) {}
+}
diff --git a/pkg/front_end/lib/src/byte_store/cache.dart b/pkg/analyzer/lib/src/dart/analysis/cache.dart
similarity index 100%
rename from pkg/front_end/lib/src/byte_store/cache.dart
rename to pkg/analyzer/lib/src/dart/analysis/cache.dart
diff --git a/pkg/analyzer/lib/src/dart/analysis/context_builder.dart b/pkg/analyzer/lib/src/dart/analysis/context_builder.dart
index 4978734..f835eb6 100644
--- a/pkg/analyzer/lib/src/dart/analysis/context_builder.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/context_builder.dart
@@ -21,7 +21,7 @@
 import 'package:analyzer/src/generated/source.dart' show ContentCache;
 import 'package:analyzer/src/dart/analysis/performance_logger.dart'
     show PerformanceLog;
-import 'package:front_end/src/byte_store/byte_store.dart'
+import 'package:analyzer/src/dart/analysis/byte_store.dart'
     show ByteStore, MemoryByteStore;
 import 'package:meta/meta.dart';
 
diff --git a/pkg/analyzer/lib/src/dart/analysis/context_locator.dart b/pkg/analyzer/lib/src/dart/analysis/context_locator.dart
index a0f0153..4422823 100644
--- a/pkg/analyzer/lib/src/dart/analysis/context_locator.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/context_locator.dart
@@ -24,7 +24,8 @@
 import 'package:analyzer/src/generated/source.dart' show ContentCache;
 import 'package:analyzer/src/dart/analysis/performance_logger.dart'
     show PerformanceLog;
-import 'package:front_end/src/byte_store/byte_store.dart' show MemoryByteStore;
+import 'package:analyzer/src/dart/analysis/byte_store.dart'
+    show MemoryByteStore;
 import 'package:meta/meta.dart';
 
 /**
diff --git a/pkg/front_end/lib/src/byte_store/crc32.dart b/pkg/analyzer/lib/src/dart/analysis/crc32.dart
similarity index 100%
rename from pkg/front_end/lib/src/byte_store/crc32.dart
rename to pkg/analyzer/lib/src/dart/analysis/crc32.dart
diff --git a/pkg/analyzer/lib/src/dart/analysis/driver.dart b/pkg/analyzer/lib/src/dart/analysis/driver.dart
index f73461a..453c116 100644
--- a/pkg/analyzer/lib/src/dart/analysis/driver.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/driver.dart
@@ -41,7 +41,7 @@
 import 'package:analyzer/src/summary/format.dart';
 import 'package:analyzer/src/summary/idl.dart';
 import 'package:analyzer/src/summary/package_bundle_reader.dart';
-import 'package:front_end/src/api_prototype/byte_store.dart';
+import 'package:analyzer/src/dart/analysis/byte_store.dart';
 import 'package:analyzer/src/summary/api_signature.dart';
 import 'package:analyzer/src/dart/analysis/performance_logger.dart';
 import 'package:meta/meta.dart';
diff --git a/pkg/analyzer/lib/src/dart/analysis/file_byte_store.dart b/pkg/analyzer/lib/src/dart/analysis/file_byte_store.dart
index 54ddf7e..8b06333 100644
--- a/pkg/analyzer/lib/src/dart/analysis/file_byte_store.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/file_byte_store.dart
@@ -1,8 +1,296 @@
-// Copyright (c) 2017, the Dart project authors.  Please see the AUTHORS file
+// Copyright (c) 2015, the Dart project authors.  Please see the AUTHORS file
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// This library re-exports the parts of front_end's file_byte_store.dart whose
-// API is stable enough to be relied upon by clients.
+import 'dart:async';
+import 'dart:io';
+import 'dart:isolate';
+import 'dart:typed_data';
 
-export 'package:front_end/src/api_prototype/byte_store.dart' show FileByteStore;
+import 'package:path/path.dart';
+
+import 'byte_store.dart';
+import 'fletcher16.dart';
+
+/**
+ * The request that is sent from the main isolate to the clean-up isolate.
+ */
+class CacheCleanUpRequest {
+  final String cachePath;
+  final int maxSizeBytes;
+  final SendPort replyTo;
+
+  CacheCleanUpRequest(this.cachePath, this.maxSizeBytes, this.replyTo);
+}
+
+/**
+ * [ByteStore] that stores values as files and performs cache eviction.
+ *
+ * Only the process that manages the cache, e.g. Analysis Server, should use
+ * this class. Other processes, e.g. Analysis Server plugins, should use
+ * [FileByteStore] instead and let the main process to perform eviction.
+ */
+class EvictingFileByteStore implements ByteStore {
+  static bool _cleanUpSendPortShouldBePrepared = true;
+  static SendPort _cleanUpSendPort;
+
+  final String _cachePath;
+  final int _maxSizeBytes;
+  final FileByteStore _fileByteStore;
+
+  int _bytesWrittenSinceCleanup = 0;
+  bool _evictionIsolateIsRunning = false;
+
+  EvictingFileByteStore(this._cachePath, this._maxSizeBytes)
+      : _fileByteStore = new FileByteStore(_cachePath) {
+    _requestCacheCleanUp();
+  }
+
+  @override
+  List<int> get(String key) => _fileByteStore.get(key);
+
+  @override
+  void put(String key, List<int> bytes) {
+    _fileByteStore.put(key, bytes);
+    // Update the current size.
+    _bytesWrittenSinceCleanup += bytes.length;
+    if (_bytesWrittenSinceCleanup > _maxSizeBytes ~/ 8) {
+      _requestCacheCleanUp();
+    }
+  }
+
+  /**
+   * If the cache clean up process has not been requested yet, request it.
+   */
+  Future<Null> _requestCacheCleanUp() async {
+    if (_cleanUpSendPortShouldBePrepared) {
+      _cleanUpSendPortShouldBePrepared = false;
+      ReceivePort response = new ReceivePort();
+      await Isolate.spawn(_cacheCleanUpFunction, response.sendPort);
+      _cleanUpSendPort = await response.first as SendPort;
+    } else {
+      while (_cleanUpSendPort == null) {
+        await new Future.delayed(new Duration(milliseconds: 100), () {});
+      }
+    }
+
+    if (!_evictionIsolateIsRunning) {
+      _evictionIsolateIsRunning = true;
+      try {
+        ReceivePort response = new ReceivePort();
+        _cleanUpSendPort.send(new CacheCleanUpRequest(
+            _cachePath, _maxSizeBytes, response.sendPort));
+        await response.first;
+      } finally {
+        _evictionIsolateIsRunning = false;
+        _bytesWrittenSinceCleanup = 0;
+      }
+    }
+  }
+
+  /**
+   * This function is started in a new isolate, receives cache folder clean up
+   * requests and evicts older files from the folder.
+   */
+  static void _cacheCleanUpFunction(message) {
+    SendPort initialReplyTo = message;
+    ReceivePort port = new ReceivePort();
+    initialReplyTo.send(port.sendPort);
+    port.listen((request) {
+      if (request is CacheCleanUpRequest) {
+        _cleanUpFolder(request.cachePath, request.maxSizeBytes);
+        // Let the client know that we're done.
+        request.replyTo.send(true);
+      }
+    });
+  }
+
+  static void _cleanUpFolder(String cachePath, int maxSizeBytes) {
+    // Prepare the list of files and their statistics.
+    List<File> files = <File>[];
+    Map<File, FileStat> fileStatMap = {};
+    int currentSizeBytes = 0;
+    List<FileSystemEntity> resources = new Directory(cachePath).listSync();
+    for (FileSystemEntity resource in resources) {
+      if (resource is File) {
+        try {
+          final FileStat fileStat = resource.statSync();
+          // Make sure that the file was not deleted out from under us (a return
+          // value of FileSystemEntityType.notFound).
+          if (fileStat.type == FileSystemEntityType.file) {
+            files.add(resource);
+            fileStatMap[resource] = fileStat;
+            currentSizeBytes += fileStat.size;
+          }
+        } catch (_) {}
+      }
+    }
+    files.sort((a, b) {
+      return fileStatMap[a].accessed.millisecondsSinceEpoch -
+          fileStatMap[b].accessed.millisecondsSinceEpoch;
+    });
+
+    // Delete files until the current size is less than the max.
+    for (File file in files) {
+      if (currentSizeBytes < maxSizeBytes) {
+        break;
+      }
+      try {
+        file.deleteSync();
+      } catch (_) {}
+      currentSizeBytes -= fileStatMap[file].size;
+    }
+  }
+}
+
+/**
+ * [ByteStore] that stores values as files.
+ */
+class FileByteStore implements ByteStore {
+  static final FileByteStoreValidator _validator = new FileByteStoreValidator();
+
+  final String _cachePath;
+  final String _tempSuffix;
+  final Map<String, List<int>> _writeInProgress = {};
+  final FuturePool _pool = new FuturePool(20);
+
+  /**
+   * If the same cache path is used from more than one isolate of the same
+   * process, then a unique [tempNameSuffix] must be provided for each isolate.
+   */
+  FileByteStore(this._cachePath, {String tempNameSuffix: ''})
+      : _tempSuffix =
+            '-temp-${pid}${tempNameSuffix.isEmpty ? '' : '-$tempNameSuffix'}';
+
+  @override
+  List<int> get(String key) {
+    List<int> bytes = _writeInProgress[key];
+    if (bytes != null) {
+      return bytes;
+    }
+
+    try {
+      final File file = _getFileForKey(key);
+      if (!file.existsSync()) {
+        return null;
+      }
+      return _validator.getData(file.readAsBytesSync());
+    } catch (_) {
+      // ignore exceptions
+      return null;
+    }
+  }
+
+  @override
+  void put(String key, List<int> bytes) {
+    _writeInProgress[key] = bytes;
+
+    final List<int> wrappedBytes = _validator.wrapData(bytes);
+
+    // We don't wait for the write and rename to complete.
+    _pool.execute(() {
+      final File tempFile = _getFileForKey('$key$_tempSuffix');
+      return tempFile.writeAsBytes(wrappedBytes).then((_) {
+        return tempFile.rename(join(_cachePath, key));
+      }).catchError((_) {
+        // ignore exceptions
+      }).whenComplete(() {
+        if (_writeInProgress[key] == bytes) {
+          _writeInProgress.remove(key);
+        }
+      });
+    });
+  }
+
+  File _getFileForKey(String key) => new File(join(_cachePath, key));
+}
+
+/**
+ * Generally speaking, we cannot guarantee that any data written into a file
+ * will stay the same - there is always a chance of a hardware problem, file
+ * system problem, truncated data, etc.
+ *
+ * So, we need to embed some validation into data itself. This class append the
+ * version and the checksum to data.
+ */
+class FileByteStoreValidator {
+  static const List<int> _VERSION = const [0x01, 0x00];
+
+  /**
+   * If the [rawBytes] have the valid version and checksum, extract and
+   * return the data from it. Otherwise return `null`.
+   */
+  List<int> getData(List<int> rawBytes) {
+    // There must be at least the version and the checksum in the raw bytes.
+    if (rawBytes.length < 4) {
+      return null;
+    }
+    int len = rawBytes.length - 4;
+
+    // Check the version.
+    if (rawBytes[len + 0] != _VERSION[0] || rawBytes[len + 1] != _VERSION[1]) {
+      return null;
+    }
+
+    // Check the checksum of the data.
+    List<int> data = rawBytes.sublist(0, len);
+    int checksum = fletcher16(data);
+    if (rawBytes[len + 2] != checksum & 0xFF ||
+        rawBytes[len + 3] != (checksum >> 8) & 0xFF) {
+      return null;
+    }
+
+    // OK, the data is probably valid.
+    return data;
+  }
+
+  /**
+   * Return bytes that include the given [data] plus the current version and
+   * the checksum of the [data].
+   */
+  List<int> wrapData(List<int> data) {
+    int len = data.length;
+    var bytes = new Uint8List(len + 4);
+
+    // Put the data.
+    bytes.setRange(0, len, data);
+
+    // Put the version.
+    bytes[len + 0] = _VERSION[0];
+    bytes[len + 1] = _VERSION[1];
+
+    // Put the checksum of the data.
+    int checksum = fletcher16(data);
+    bytes[len + 2] = checksum & 0xFF;
+    bytes[len + 3] = (checksum >> 8) & 0xFF;
+
+    return bytes;
+  }
+}
+
+class FuturePool {
+  int _available;
+  List waiting = [];
+
+  FuturePool(this._available);
+
+  void execute(Future Function() fn) {
+    if (_available > 0) {
+      _run(fn);
+    } else {
+      waiting.add(fn);
+    }
+  }
+
+  void _run(Future Function() fn) {
+    _available--;
+
+    fn().whenComplete(() {
+      _available++;
+
+      if (waiting.isNotEmpty) {
+        _run(waiting.removeAt(0));
+      }
+    });
+  }
+}
diff --git a/pkg/analyzer/lib/src/dart/analysis/file_state.dart b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
index 6bd09b9..fe5cec4 100644
--- a/pkg/analyzer/lib/src/dart/analysis/file_state.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
@@ -29,7 +29,7 @@
 import 'package:analyzer/src/summary/summarize_ast.dart';
 import 'package:convert/convert.dart';
 import 'package:crypto/crypto.dart';
-import 'package:front_end/src/api_prototype/byte_store.dart';
+import 'package:analyzer/src/dart/analysis/byte_store.dart';
 import 'package:analyzer/src/summary/api_signature.dart';
 import 'package:analyzer/src/dart/analysis/performance_logger.dart';
 import 'package:front_end/src/fasta/scanner/token.dart';
diff --git a/pkg/front_end/lib/src/byte_store/fletcher16.dart b/pkg/analyzer/lib/src/dart/analysis/fletcher16.dart
similarity index 100%
rename from pkg/front_end/lib/src/byte_store/fletcher16.dart
rename to pkg/analyzer/lib/src/dart/analysis/fletcher16.dart
diff --git a/pkg/analyzer/lib/src/dart/analysis/library_context.dart b/pkg/analyzer/lib/src/dart/analysis/library_context.dart
index c0fef6f..643c870 100644
--- a/pkg/analyzer/lib/src/dart/analysis/library_context.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/library_context.dart
@@ -21,7 +21,7 @@
 import 'package:analyzer/src/summary/one_phase.dart';
 import 'package:analyzer/src/summary/package_bundle_reader.dart';
 import 'package:analyzer/src/summary/summarize_elements.dart';
-import 'package:front_end/src/api_prototype/byte_store.dart';
+import 'package:analyzer/src/dart/analysis/byte_store.dart';
 import 'package:analyzer/src/dart/analysis/performance_logger.dart';
 
 /**
diff --git a/pkg/front_end/lib/src/byte_store/protected_file_byte_store.dart b/pkg/analyzer/lib/src/dart/analysis/protected_file_byte_store.dart
similarity index 100%
rename from pkg/front_end/lib/src/byte_store/protected_file_byte_store.dart
rename to pkg/analyzer/lib/src/dart/analysis/protected_file_byte_store.dart
diff --git a/pkg/analyzer/lib/src/lint/analysis.dart b/pkg/analyzer/lib/src/lint/analysis.dart
index 4baf120..bc4e089 100644
--- a/pkg/analyzer/lib/src/lint/analysis.dart
+++ b/pkg/analyzer/lib/src/lint/analysis.dart
@@ -25,7 +25,7 @@
 import 'package:analyzer/src/services/lint.dart';
 import 'package:analyzer/src/source/package_map_resolver.dart';
 import 'package:analyzer/src/util/sdk.dart';
-import 'package:front_end/src/api_prototype/byte_store.dart';
+import 'package:analyzer/src/dart/analysis/byte_store.dart';
 import 'package:analyzer/src/dart/analysis/performance_logger.dart';
 import 'package:package_config/packages.dart' show Packages;
 import 'package:package_config/packages_file.dart' as pkgfile show parse;
diff --git a/pkg/analyzer/test/generated/resolver_test_case.dart b/pkg/analyzer/test/generated/resolver_test_case.dart
index acfb679..d7a954d 100644
--- a/pkg/analyzer/test/generated/resolver_test_case.dart
+++ b/pkg/analyzer/test/generated/resolver_test_case.dart
@@ -26,7 +26,7 @@
 import 'package:analyzer/src/generated/testing/ast_test_factory.dart';
 import 'package:analyzer/src/generated/testing/element_factory.dart';
 import 'package:analyzer/src/source/package_map_resolver.dart';
-import 'package:front_end/src/api_prototype/byte_store.dart';
+import 'package:analyzer/src/dart/analysis/byte_store.dart';
 import 'package:analyzer/src/dart/analysis/performance_logger.dart';
 import 'package:test/test.dart';
 
diff --git a/pkg/analyzer/test/src/dart/analysis/base.dart b/pkg/analyzer/test/src/dart/analysis/base.dart
index d3f0b3f..e9f6eaa 100644
--- a/pkg/analyzer/test/src/dart/analysis/base.dart
+++ b/pkg/analyzer/test/src/dart/analysis/base.dart
@@ -16,7 +16,7 @@
 import 'package:analyzer/src/generated/source.dart';
 import 'package:analyzer/src/source/package_map_resolver.dart';
 import 'package:analyzer/src/summary/package_bundle_reader.dart';
-import 'package:front_end/src/api_prototype/byte_store.dart';
+import 'package:analyzer/src/dart/analysis/byte_store.dart';
 import 'package:analyzer/src/dart/analysis/performance_logger.dart';
 import 'package:test/test.dart';
 
diff --git a/pkg/front_end/test/src/byte_store/byte_store_test.dart b/pkg/analyzer/test/src/dart/analysis/byte_store_test.dart
similarity index 97%
rename from pkg/front_end/test/src/byte_store/byte_store_test.dart
rename to pkg/analyzer/test/src/dart/analysis/byte_store_test.dart
index 28e77ac..ad06c6a 100644
--- a/pkg/front_end/test/src/byte_store/byte_store_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/byte_store_test.dart
@@ -2,7 +2,7 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-import 'package:front_end/src/byte_store/byte_store.dart';
+import 'package:analyzer/src/dart/analysis/byte_store.dart';
 import 'package:test/test.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
diff --git a/pkg/front_end/test/src/byte_store/cache_test.dart b/pkg/analyzer/test/src/dart/analysis/cache_test.dart
similarity index 97%
rename from pkg/front_end/test/src/byte_store/cache_test.dart
rename to pkg/analyzer/test/src/dart/analysis/cache_test.dart
index 6221e43..20f190d 100644
--- a/pkg/front_end/test/src/byte_store/cache_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/cache_test.dart
@@ -2,7 +2,7 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-import 'package:front_end/src/byte_store/cache.dart';
+import 'package:analyzer/src/dart/analysis/cache.dart';
 import 'package:test/test.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
diff --git a/pkg/front_end/test/src/byte_store/crc32_test.dart b/pkg/analyzer/test/src/dart/analysis/crc32_test.dart
similarity index 93%
rename from pkg/front_end/test/src/byte_store/crc32_test.dart
rename to pkg/analyzer/test/src/dart/analysis/crc32_test.dart
index 0d209bb..2480507 100644
--- a/pkg/front_end/test/src/byte_store/crc32_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/crc32_test.dart
@@ -4,7 +4,7 @@
 
 import 'dart:convert';
 
-import 'package:front_end/src/byte_store/crc32.dart';
+import 'package:analyzer/src/dart/analysis/crc32.dart';
 import 'package:test/test.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
diff --git a/pkg/analyzer/test/src/dart/analysis/driver_test.dart b/pkg/analyzer/test/src/dart/analysis/driver_test.dart
index adbf145..b0adc84 100644
--- a/pkg/analyzer/test/src/dart/analysis/driver_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/driver_test.dart
@@ -24,7 +24,7 @@
 import 'package:analyzer/src/generated/source.dart';
 import 'package:analyzer/src/summary/idl.dart';
 import 'package:analyzer/src/summary/package_bundle_reader.dart';
-import 'package:front_end/src/api_prototype/byte_store.dart';
+import 'package:analyzer/src/dart/analysis/byte_store.dart';
 import 'package:analyzer/src/dart/analysis/performance_logger.dart';
 import 'package:test/test.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
diff --git a/pkg/front_end/test/src/byte_store/file_byte_store_test.dart b/pkg/analyzer/test/src/dart/analysis/file_byte_store_test.dart
similarity index 95%
rename from pkg/front_end/test/src/byte_store/file_byte_store_test.dart
rename to pkg/analyzer/test/src/dart/analysis/file_byte_store_test.dart
index a2aa7ed..5975150 100644
--- a/pkg/front_end/test/src/byte_store/file_byte_store_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/file_byte_store_test.dart
@@ -2,7 +2,7 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-import 'package:front_end/src/byte_store/file_byte_store.dart';
+import 'package:analyzer/src/dart/analysis/file_byte_store.dart';
 import 'package:test/test.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
diff --git a/pkg/analyzer/test/src/dart/analysis/file_state_test.dart b/pkg/analyzer/test/src/dart/analysis/file_state_test.dart
index 421fe06..1bbdb6d 100644
--- a/pkg/analyzer/test/src/dart/analysis/file_state_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/file_state_test.dart
@@ -16,7 +16,7 @@
 import 'package:analyzer/src/source/package_map_resolver.dart';
 import 'package:convert/convert.dart';
 import 'package:crypto/crypto.dart';
-import 'package:front_end/src/api_prototype/byte_store.dart';
+import 'package:analyzer/src/dart/analysis/byte_store.dart';
 import 'package:analyzer/src/dart/analysis/performance_logger.dart';
 import 'package:test/test.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
diff --git a/pkg/front_end/test/src/byte_store/fletcher16_test.dart b/pkg/analyzer/test/src/dart/analysis/fletcher16_test.dart
similarity index 92%
rename from pkg/front_end/test/src/byte_store/fletcher16_test.dart
rename to pkg/analyzer/test/src/dart/analysis/fletcher16_test.dart
index a80dcc8..e44e3a7 100644
--- a/pkg/front_end/test/src/byte_store/fletcher16_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/fletcher16_test.dart
@@ -2,7 +2,7 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-import 'package:front_end/src/byte_store/fletcher16.dart';
+import 'package:analyzer/src/dart/analysis/fletcher16.dart';
 import 'package:test/test.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
diff --git a/pkg/front_end/test/src/byte_store/protected_file_byte_store_test.dart b/pkg/analyzer/test/src/dart/analysis/protected_file_byte_store_test.dart
similarity index 98%
rename from pkg/front_end/test/src/byte_store/protected_file_byte_store_test.dart
rename to pkg/analyzer/test/src/dart/analysis/protected_file_byte_store_test.dart
index ad88088..05bcad5 100644
--- a/pkg/front_end/test/src/byte_store/protected_file_byte_store_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/protected_file_byte_store_test.dart
@@ -5,7 +5,7 @@
 import 'dart:async';
 import 'dart:io' as io;
 
-import 'package:front_end/src/byte_store/protected_file_byte_store.dart';
+import 'package:analyzer/src/dart/analysis/protected_file_byte_store.dart';
 import 'package:path/path.dart' as pathos;
 import 'package:test/test.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
diff --git a/pkg/analyzer/test/src/dart/analysis/test_all.dart b/pkg/analyzer/test/src/dart/analysis/test_all.dart
index f4f9c49..ac21ffc 100644
--- a/pkg/analyzer/test/src/dart/analysis/test_all.dart
+++ b/pkg/analyzer/test/src/dart/analysis/test_all.dart
@@ -5,15 +5,21 @@
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 import 'analysis_context_collection_test.dart' as analysis_context_collection;
+import 'byte_store_test.dart' as byte_store_test;
+import 'cache_test.dart' as cache_test;
 import 'context_builder_test.dart' as context_builder;
 import 'context_locator_test.dart' as context_locator;
 import 'context_root_test.dart' as context_root;
+import 'crc32_test.dart' as crc32_test;
 import 'defined_names_test.dart' as defined_names;
 import 'driver_resolution_test.dart' as driver_resolution;
 import 'driver_test.dart' as driver;
+import 'file_byte_store_test.dart' as file_byte_store_test;
 import 'file_state_test.dart' as file_state;
+import 'fletcher16_test.dart' as fletcher16_test;
 import 'index_test.dart' as index;
 import 'mutex_test.dart' as mutex;
+import 'protected_file_byte_store_test.dart' as protected_file_byte_store_test;
 import 'referenced_names_test.dart' as referenced_names;
 import 'search_test.dart' as search;
 import 'session_helper_test.dart' as session_helper;
@@ -24,19 +30,25 @@
 main() {
   defineReflectiveSuite(() {
     analysis_context_collection.main();
+    byte_store_test.main();
+    cache_test.main();
     context_builder.main();
     context_locator.main();
     context_root.main();
+    crc32_test.main();
     defined_names.main();
     driver.main();
     driver_resolution.main();
+    file_byte_store_test.main();
     file_state.main();
+    fletcher16_test.main();
     index.main();
     mutex.main();
+    protected_file_byte_store_test.main();
     referenced_names.main();
     search.main();
-    session_helper.main();
     session.main();
+    session_helper.main();
     unlinked_api_signature.main();
     uri_converter.main();
   }, name: 'analysis');
diff --git a/pkg/analyzer/test/src/dart/analysis/unlinked_api_signature_test.dart b/pkg/analyzer/test/src/dart/analysis/unlinked_api_signature_test.dart
index 99b9c64..2ef0d59 100644
--- a/pkg/analyzer/test/src/dart/analysis/unlinked_api_signature_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/unlinked_api_signature_test.dart
@@ -12,7 +12,7 @@
 import 'package:analyzer/src/generated/source.dart';
 import 'package:analyzer/src/source/package_map_resolver.dart';
 import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
-import 'package:front_end/src/api_prototype/byte_store.dart';
+import 'package:analyzer/src/dart/analysis/byte_store.dart';
 import 'package:analyzer/src/dart/analysis/performance_logger.dart';
 import 'package:test/test.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
diff --git a/pkg/analyzer/test/src/task/strong/strong_test_helper.dart b/pkg/analyzer/test/src/task/strong/strong_test_helper.dart
index 1ec0712..86eadb4 100644
--- a/pkg/analyzer/test/src/task/strong/strong_test_helper.dart
+++ b/pkg/analyzer/test/src/task/strong/strong_test_helper.dart
@@ -23,7 +23,7 @@
 import 'package:analyzer/src/file_system/file_system.dart';
 import 'package:analyzer/src/generated/engine.dart';
 import 'package:analyzer/src/generated/source.dart';
-import 'package:front_end/src/api_prototype/byte_store.dart';
+import 'package:analyzer/src/dart/analysis/byte_store.dart';
 import 'package:analyzer/src/dart/analysis/performance_logger.dart';
 import 'package:source_span/source_span.dart';
 import 'package:test/test.dart';
diff --git a/pkg/analyzer/tool/task_dependency_graph/generate.dart b/pkg/analyzer/tool/task_dependency_graph/generate.dart
index 07a3aa5..739ac6c 100644
--- a/pkg/analyzer/tool/task_dependency_graph/generate.dart
+++ b/pkg/analyzer/tool/task_dependency_graph/generate.dart
@@ -35,7 +35,7 @@
 import 'package:analyzer/src/generated/source.dart';
 import 'package:analyzer/src/generated/source_io.dart';
 import 'package:analyzer/src/source/package_map_resolver.dart';
-import 'package:front_end/src/api_prototype/byte_store.dart';
+import 'package:analyzer/src/dart/analysis/byte_store.dart';
 import 'package:analyzer/src/dart/analysis/performance_logger.dart';
 import 'package:analyzer/src/codegen/tools.dart';
 import 'package:front_end/src/testing/package_root.dart' as package_root;
diff --git a/pkg/analyzer_cli/lib/src/build_mode.dart b/pkg/analyzer_cli/lib/src/build_mode.dart
index 0ae6459..95b79f2 100644
--- a/pkg/analyzer_cli/lib/src/build_mode.dart
+++ b/pkg/analyzer_cli/lib/src/build_mode.dart
@@ -34,9 +34,9 @@
 import 'package:bazel_worker/bazel_worker.dart';
 import 'package:collection/collection.dart';
 import 'package:convert/convert.dart';
-import 'package:front_end/src/api_prototype/byte_store.dart';
+import 'package:analyzer/src/dart/analysis/byte_store.dart';
 import 'package:analyzer/src/dart/analysis/performance_logger.dart';
-import 'package:front_end/src/byte_store/cache.dart';
+import 'package:analyzer/src/dart/analysis/cache.dart';
 
 /**
  * Persistent Bazel worker.
diff --git a/pkg/analyzer_cli/lib/src/driver.dart b/pkg/analyzer_cli/lib/src/driver.dart
index e4a29f9..cb36d12 100644
--- a/pkg/analyzer_cli/lib/src/driver.dart
+++ b/pkg/analyzer_cli/lib/src/driver.dart
@@ -43,7 +43,7 @@
 import 'package:analyzer_cli/src/options.dart';
 import 'package:analyzer_cli/src/perf_report.dart';
 import 'package:analyzer_cli/starter.dart' show CommandLineStarter;
-import 'package:front_end/src/api_prototype/byte_store.dart';
+import 'package:analyzer/src/dart/analysis/byte_store.dart';
 import 'package:analyzer/src/dart/analysis/performance_logger.dart';
 import 'package:linter/src/rules.dart' as linter;
 import 'package:meta/meta.dart';
diff --git a/pkg/front_end/lib/src/api_prototype/byte_store.dart b/pkg/front_end/lib/src/api_prototype/byte_store.dart
deleted file mode 100644
index b44bb6e..0000000
--- a/pkg/front_end/lib/src/api_prototype/byte_store.dart
+++ /dev/null
@@ -1,10 +0,0 @@
-// Copyright (c) 2017, the Dart project authors.  Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-library front_end.byte_store;
-
-export '../byte_store/byte_store.dart'
-    show ByteStore, MemoryByteStore, MemoryCachingByteStore, NullByteStore;
-export '../byte_store/file_byte_store.dart'
-    show EvictingFileByteStore, FileByteStore;
diff --git a/pkg/front_end/lib/src/api_prototype/compiler_options.dart b/pkg/front_end/lib/src/api_prototype/compiler_options.dart
index 865c71e..076ec72 100644
--- a/pkg/front_end/lib/src/api_prototype/compiler_options.dart
+++ b/pkg/front_end/lib/src/api_prototype/compiler_options.dart
@@ -10,8 +10,6 @@
 
 import '../fasta/severity.dart' show Severity;
 
-import 'byte_store.dart' show ByteStore, NullByteStore;
-
 import 'compilation_message.dart' show CompilationMessage;
 
 import 'diagnostic_message.dart' show DiagnosticMessageHandler;
@@ -130,9 +128,6 @@
   /// file system.  TODO(paulberry): fix this.
   FileSystem fileSystem = StandardFileSystem.instance;
 
-  /// The byte storage to access serialized data.
-  ByteStore byteStore = new NullByteStore();
-
   /// Whether to generate code for the SDK.
   ///
   /// By default the front end resolves components using a prebuilt SDK summary.
diff --git a/pkg/front_end/lib/src/base/processed_options.dart b/pkg/front_end/lib/src/base/processed_options.dart
index b47bfae..b4268ca 100644
--- a/pkg/front_end/lib/src/base/processed_options.dart
+++ b/pkg/front_end/lib/src/base/processed_options.dart
@@ -21,8 +21,6 @@
 
 import 'package:source_span/source_span.dart' show SourceSpan, SourceLocation;
 
-import '../api_prototype/byte_store.dart' show ByteStore;
-
 import '../api_prototype/compilation_message.dart' show CompilationMessage;
 
 import '../api_prototype/compiler_options.dart' show CompilerOptions;
@@ -181,11 +179,6 @@
         // collecting time since the start of the VM.
         this.ticker = new Ticker(isVerbose: options?.verbose ?? false);
 
-  /// The byte storage to get and put serialized data.
-  ByteStore get byteStore {
-    return _raw.byteStore;
-  }
-
   bool get _reportMessages {
     return _raw.onProblem == null &&
         (_raw.reportMessages ?? (_raw.onError == null));
diff --git a/pkg/front_end/lib/src/byte_store/byte_store.dart b/pkg/front_end/lib/src/byte_store/byte_store.dart
index 80f7b32..27f9bad 100644
--- a/pkg/front_end/lib/src/byte_store/byte_store.dart
+++ b/pkg/front_end/lib/src/byte_store/byte_store.dart
@@ -1,80 +1,11 @@
-// Copyright (c) 2015, the Dart project authors.  Please see the AUTHORS file
+// Copyright (c) 2018, the Dart project authors.  Please see the AUTHORS file
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-import 'cache.dart';
+/// This is deprecated, please use
+/// `package:analyzer/src/dart/analysis/byte_store.dart` instead.
+@deprecated
+library front_end.byte_store;
 
-/**
- * Store of bytes associated with string keys.
- *
- * Each key must be not longer than 100 characters and consist of only `[a-z]`,
- * `[0-9]`, `.` and `_` characters. The key cannot be an empty string, the
- * literal `.`, or contain the sequence `..`.
- *
- * Note that associations are not guaranteed to be persistent. The value
- * associated with a key can change or become `null` at any point in time.
- *
- * TODO(scheglov) Research using asynchronous API.
- */
-abstract class ByteStore {
-  /**
-   * Return the bytes associated with the given [key].
-   * Return `null` if the association does not exist.
-   */
-  List<int> get(String key);
-
-  /**
-   * Associate the given [bytes] with the [key].
-   */
-  void put(String key, List<int> bytes);
-}
-
-/**
- * [ByteStore] which stores data only in memory.
- */
-class MemoryByteStore implements ByteStore {
-  final Map<String, List<int>> _map = {};
-
-  @override
-  List<int> get(String key) {
-    return _map[key];
-  }
-
-  @override
-  void put(String key, List<int> bytes) {
-    _map[key] = bytes;
-  }
-}
-
-/**
- * A wrapper around [ByteStore] which adds an in-memory LRU cache to it.
- */
-class MemoryCachingByteStore implements ByteStore {
-  final ByteStore _store;
-  final Cache<String, List<int>> _cache;
-
-  MemoryCachingByteStore(this._store, int maxSizeBytes)
-      : _cache = new Cache<String, List<int>>(maxSizeBytes, (v) => v.length);
-
-  @override
-  List<int> get(String key) {
-    return _cache.get(key, () => _store.get(key));
-  }
-
-  @override
-  void put(String key, List<int> bytes) {
-    _store.put(key, bytes);
-    _cache.put(key, bytes);
-  }
-}
-
-/**
- * [ByteStore] which does not store any data.
- */
-class NullByteStore implements ByteStore {
-  @override
-  List<int> get(String key) => null;
-
-  @override
-  void put(String key, List<int> bytes) {}
-}
+export 'package:analyzer/src/dart/analysis/byte_store.dart'
+    show MemoryByteStore;
diff --git a/pkg/front_end/lib/src/byte_store/file_byte_store.dart b/pkg/front_end/lib/src/byte_store/file_byte_store.dart
deleted file mode 100644
index 8b06333..0000000
--- a/pkg/front_end/lib/src/byte_store/file_byte_store.dart
+++ /dev/null
@@ -1,296 +0,0 @@
-// Copyright (c) 2015, the Dart project authors.  Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-import 'dart:async';
-import 'dart:io';
-import 'dart:isolate';
-import 'dart:typed_data';
-
-import 'package:path/path.dart';
-
-import 'byte_store.dart';
-import 'fletcher16.dart';
-
-/**
- * The request that is sent from the main isolate to the clean-up isolate.
- */
-class CacheCleanUpRequest {
-  final String cachePath;
-  final int maxSizeBytes;
-  final SendPort replyTo;
-
-  CacheCleanUpRequest(this.cachePath, this.maxSizeBytes, this.replyTo);
-}
-
-/**
- * [ByteStore] that stores values as files and performs cache eviction.
- *
- * Only the process that manages the cache, e.g. Analysis Server, should use
- * this class. Other processes, e.g. Analysis Server plugins, should use
- * [FileByteStore] instead and let the main process to perform eviction.
- */
-class EvictingFileByteStore implements ByteStore {
-  static bool _cleanUpSendPortShouldBePrepared = true;
-  static SendPort _cleanUpSendPort;
-
-  final String _cachePath;
-  final int _maxSizeBytes;
-  final FileByteStore _fileByteStore;
-
-  int _bytesWrittenSinceCleanup = 0;
-  bool _evictionIsolateIsRunning = false;
-
-  EvictingFileByteStore(this._cachePath, this._maxSizeBytes)
-      : _fileByteStore = new FileByteStore(_cachePath) {
-    _requestCacheCleanUp();
-  }
-
-  @override
-  List<int> get(String key) => _fileByteStore.get(key);
-
-  @override
-  void put(String key, List<int> bytes) {
-    _fileByteStore.put(key, bytes);
-    // Update the current size.
-    _bytesWrittenSinceCleanup += bytes.length;
-    if (_bytesWrittenSinceCleanup > _maxSizeBytes ~/ 8) {
-      _requestCacheCleanUp();
-    }
-  }
-
-  /**
-   * If the cache clean up process has not been requested yet, request it.
-   */
-  Future<Null> _requestCacheCleanUp() async {
-    if (_cleanUpSendPortShouldBePrepared) {
-      _cleanUpSendPortShouldBePrepared = false;
-      ReceivePort response = new ReceivePort();
-      await Isolate.spawn(_cacheCleanUpFunction, response.sendPort);
-      _cleanUpSendPort = await response.first as SendPort;
-    } else {
-      while (_cleanUpSendPort == null) {
-        await new Future.delayed(new Duration(milliseconds: 100), () {});
-      }
-    }
-
-    if (!_evictionIsolateIsRunning) {
-      _evictionIsolateIsRunning = true;
-      try {
-        ReceivePort response = new ReceivePort();
-        _cleanUpSendPort.send(new CacheCleanUpRequest(
-            _cachePath, _maxSizeBytes, response.sendPort));
-        await response.first;
-      } finally {
-        _evictionIsolateIsRunning = false;
-        _bytesWrittenSinceCleanup = 0;
-      }
-    }
-  }
-
-  /**
-   * This function is started in a new isolate, receives cache folder clean up
-   * requests and evicts older files from the folder.
-   */
-  static void _cacheCleanUpFunction(message) {
-    SendPort initialReplyTo = message;
-    ReceivePort port = new ReceivePort();
-    initialReplyTo.send(port.sendPort);
-    port.listen((request) {
-      if (request is CacheCleanUpRequest) {
-        _cleanUpFolder(request.cachePath, request.maxSizeBytes);
-        // Let the client know that we're done.
-        request.replyTo.send(true);
-      }
-    });
-  }
-
-  static void _cleanUpFolder(String cachePath, int maxSizeBytes) {
-    // Prepare the list of files and their statistics.
-    List<File> files = <File>[];
-    Map<File, FileStat> fileStatMap = {};
-    int currentSizeBytes = 0;
-    List<FileSystemEntity> resources = new Directory(cachePath).listSync();
-    for (FileSystemEntity resource in resources) {
-      if (resource is File) {
-        try {
-          final FileStat fileStat = resource.statSync();
-          // Make sure that the file was not deleted out from under us (a return
-          // value of FileSystemEntityType.notFound).
-          if (fileStat.type == FileSystemEntityType.file) {
-            files.add(resource);
-            fileStatMap[resource] = fileStat;
-            currentSizeBytes += fileStat.size;
-          }
-        } catch (_) {}
-      }
-    }
-    files.sort((a, b) {
-      return fileStatMap[a].accessed.millisecondsSinceEpoch -
-          fileStatMap[b].accessed.millisecondsSinceEpoch;
-    });
-
-    // Delete files until the current size is less than the max.
-    for (File file in files) {
-      if (currentSizeBytes < maxSizeBytes) {
-        break;
-      }
-      try {
-        file.deleteSync();
-      } catch (_) {}
-      currentSizeBytes -= fileStatMap[file].size;
-    }
-  }
-}
-
-/**
- * [ByteStore] that stores values as files.
- */
-class FileByteStore implements ByteStore {
-  static final FileByteStoreValidator _validator = new FileByteStoreValidator();
-
-  final String _cachePath;
-  final String _tempSuffix;
-  final Map<String, List<int>> _writeInProgress = {};
-  final FuturePool _pool = new FuturePool(20);
-
-  /**
-   * If the same cache path is used from more than one isolate of the same
-   * process, then a unique [tempNameSuffix] must be provided for each isolate.
-   */
-  FileByteStore(this._cachePath, {String tempNameSuffix: ''})
-      : _tempSuffix =
-            '-temp-${pid}${tempNameSuffix.isEmpty ? '' : '-$tempNameSuffix'}';
-
-  @override
-  List<int> get(String key) {
-    List<int> bytes = _writeInProgress[key];
-    if (bytes != null) {
-      return bytes;
-    }
-
-    try {
-      final File file = _getFileForKey(key);
-      if (!file.existsSync()) {
-        return null;
-      }
-      return _validator.getData(file.readAsBytesSync());
-    } catch (_) {
-      // ignore exceptions
-      return null;
-    }
-  }
-
-  @override
-  void put(String key, List<int> bytes) {
-    _writeInProgress[key] = bytes;
-
-    final List<int> wrappedBytes = _validator.wrapData(bytes);
-
-    // We don't wait for the write and rename to complete.
-    _pool.execute(() {
-      final File tempFile = _getFileForKey('$key$_tempSuffix');
-      return tempFile.writeAsBytes(wrappedBytes).then((_) {
-        return tempFile.rename(join(_cachePath, key));
-      }).catchError((_) {
-        // ignore exceptions
-      }).whenComplete(() {
-        if (_writeInProgress[key] == bytes) {
-          _writeInProgress.remove(key);
-        }
-      });
-    });
-  }
-
-  File _getFileForKey(String key) => new File(join(_cachePath, key));
-}
-
-/**
- * Generally speaking, we cannot guarantee that any data written into a file
- * will stay the same - there is always a chance of a hardware problem, file
- * system problem, truncated data, etc.
- *
- * So, we need to embed some validation into data itself. This class append the
- * version and the checksum to data.
- */
-class FileByteStoreValidator {
-  static const List<int> _VERSION = const [0x01, 0x00];
-
-  /**
-   * If the [rawBytes] have the valid version and checksum, extract and
-   * return the data from it. Otherwise return `null`.
-   */
-  List<int> getData(List<int> rawBytes) {
-    // There must be at least the version and the checksum in the raw bytes.
-    if (rawBytes.length < 4) {
-      return null;
-    }
-    int len = rawBytes.length - 4;
-
-    // Check the version.
-    if (rawBytes[len + 0] != _VERSION[0] || rawBytes[len + 1] != _VERSION[1]) {
-      return null;
-    }
-
-    // Check the checksum of the data.
-    List<int> data = rawBytes.sublist(0, len);
-    int checksum = fletcher16(data);
-    if (rawBytes[len + 2] != checksum & 0xFF ||
-        rawBytes[len + 3] != (checksum >> 8) & 0xFF) {
-      return null;
-    }
-
-    // OK, the data is probably valid.
-    return data;
-  }
-
-  /**
-   * Return bytes that include the given [data] plus the current version and
-   * the checksum of the [data].
-   */
-  List<int> wrapData(List<int> data) {
-    int len = data.length;
-    var bytes = new Uint8List(len + 4);
-
-    // Put the data.
-    bytes.setRange(0, len, data);
-
-    // Put the version.
-    bytes[len + 0] = _VERSION[0];
-    bytes[len + 1] = _VERSION[1];
-
-    // Put the checksum of the data.
-    int checksum = fletcher16(data);
-    bytes[len + 2] = checksum & 0xFF;
-    bytes[len + 3] = (checksum >> 8) & 0xFF;
-
-    return bytes;
-  }
-}
-
-class FuturePool {
-  int _available;
-  List waiting = [];
-
-  FuturePool(this._available);
-
-  void execute(Future Function() fn) {
-    if (_available > 0) {
-      _run(fn);
-    } else {
-      waiting.add(fn);
-    }
-  }
-
-  void _run(Future Function() fn) {
-    _available--;
-
-    fn().whenComplete(() {
-      _available++;
-
-      if (waiting.isNotEmpty) {
-        _run(waiting.removeAt(0));
-      }
-    });
-  }
-}
diff --git a/pkg/front_end/test/src/byte_store/test_all.dart b/pkg/front_end/test/src/byte_store/test_all.dart
deleted file mode 100644
index 57ae68f..0000000
--- a/pkg/front_end/test/src/byte_store/test_all.dart
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright (c) 2017, the Dart project authors.  Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-import 'package:test_reflective_loader/test_reflective_loader.dart';
-
-import 'byte_store_test.dart' as byte_store_test;
-import 'cache_test.dart' as cache_test;
-import 'crc32_test.dart' as crc32_test;
-import 'file_byte_store_test.dart' as file_byte_store_test;
-import 'fletcher16_test.dart' as fletcher16_test;
-import 'protected_file_byte_store_test.dart' as protected_file_byte_store_test;
-
-/// Utility for manually running all tests.
-main() {
-  defineReflectiveSuite(() {
-    byte_store_test.main();
-    cache_test.main();
-    crc32_test.main();
-    file_byte_store_test.main();
-    fletcher16_test.main();
-    protected_file_byte_store_test.main();
-  }, name: 'byte_store');
-}
diff --git a/pkg/front_end/tool/incremental_perf.dart b/pkg/front_end/tool/incremental_perf.dart
index 8a28dc5..803b94b 100644
--- a/pkg/front_end/tool/incremental_perf.dart
+++ b/pkg/front_end/tool/incremental_perf.dart
@@ -47,7 +47,6 @@
 import 'dart:io' hide FileSystemEntity;
 
 import 'package:args/args.dart';
-import 'package:front_end/src/api_prototype/byte_store.dart';
 import 'package:front_end/src/api_prototype/file_system.dart'
     show FileSystemEntity;
 import 'package:front_end/src/api_prototype/front_end.dart';
@@ -55,7 +54,6 @@
 import 'package:front_end/src/api_prototype/memory_file_system.dart';
 import 'package:front_end/src/api_prototype/standard_file_system.dart';
 import 'package:front_end/src/base/processed_options.dart';
-import 'package:front_end/src/byte_store/protected_file_byte_store.dart';
 import 'package:front_end/src/fasta/uri_translator.dart';
 
 import 'perf_common.dart';
@@ -125,7 +123,6 @@
   }
 
   var dir = Directory.systemTemp.createTempSync("ikg-cache");
-  compilerOptions.byteStore = createByteStore(cache, dir.path);
 
   final processedOptions =
       new ProcessedOptions(options: compilerOptions, inputs: [entryUri]);
@@ -263,21 +260,6 @@
       _fs.memory.entityForUri(uri).writeAsStringSync(contents);
 }
 
-ByteStore createByteStore(String cachePolicy, String path) {
-  switch (cachePolicy) {
-    case 'memory':
-      return new MemoryByteStore();
-    case 'protected':
-      return new ProtectedFileByteStore(path);
-    case 'evicting':
-      return new MemoryCachingByteStore(
-          new EvictingFileByteStore(path, 1024 * 1024 * 1024 /* 1G */),
-          64 * 1024 * 1024 /* 64M */);
-    default:
-      throw new UnsupportedError('Unknown cache policy: $cachePolicy');
-  }
-}
-
 /// A string replacement edit in a source file.
 class Edit {
   final Uri uri;