Skip to content

Commit

Permalink
Enable buffering for CacheDataSink by default
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=146221487
  • Loading branch information
erdemguven authored and ojw28 committed Feb 15, 2017
1 parent 74acbe0 commit 025a67c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
*/
public final class CacheDataSink implements DataSink {

/** Default buffer size. */
public static final int DEFAULT_BUFFER_SIZE = 20480;

private final Cache cache;
private final long maxCacheFileSize;
private final int bufferSize;
Expand All @@ -56,13 +59,15 @@ public CacheDataSinkException(IOException cause) {
}

/**
* Constructs a CacheDataSink using the {@link #DEFAULT_BUFFER_SIZE}.
*
* @param cache The cache into which data should be written.
* @param maxCacheFileSize The maximum size of a cache file, in bytes. If the sink is opened for
* a {@link DataSpec} whose size exceeds this value, then the data will be fragmented into
* multiple cache files.
*/
public CacheDataSink(Cache cache, long maxCacheFileSize) {
this(cache, maxCacheFileSize, 0);
this(cache, maxCacheFileSize, DEFAULT_BUFFER_SIZE);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,27 @@ public final class CacheDataSinkFactory implements DataSink.Factory {

private final Cache cache;
private final long maxCacheFileSize;
private final int bufferSize;

/**
* @see CacheDataSink#CacheDataSink(Cache, long)
*/
public CacheDataSinkFactory(Cache cache, long maxCacheFileSize) {
this(cache, maxCacheFileSize, CacheDataSink.DEFAULT_BUFFER_SIZE);
}

/**
* @see CacheDataSink#CacheDataSink(Cache, long, int)
*/
public CacheDataSinkFactory(Cache cache, long maxCacheFileSize, int bufferSize) {
this.cache = cache;
this.maxCacheFileSize = maxCacheFileSize;
this.bufferSize = bufferSize;
}

@Override
public DataSink createDataSink() {
return new CacheDataSink(cache, maxCacheFileSize);
return new CacheDataSink(cache, maxCacheFileSize, bufferSize);
}

}

0 comments on commit 025a67c

Please sign in to comment.