Commit 613da114 authored by Fabio Pelosin's avatar Fabio Pelosin

[Config] Allow to set the size of the cache.

- This also fixes a bug which lead CocoaPods to always use the
  aggressive cache.
parent 3bb1c1af
......@@ -4,6 +4,13 @@ To install or update CocoaPods see this [guide](http://docs.cocoapods.org/guides
## Master
###### Enhancements
* The size of the cache used for the git repos is now configurable. For more
detail see
https://github.com/CocoaPods/CocoaPods/blob/master/lib/cocoapods/config.rb#L7-L25
[#1159](https://github.com/CocoaPods/CocoaPods/issues/1159)
###### Bug fixes
* Pods whose head state changes now are correctly detected and reinstalled.
......
......@@ -18,25 +18,6 @@ module Pod
end
end
# @return [Pathname] The directory where CocoaPods caches the downloads.
#
# @todo The {Installer::PodSourceInstaller} and the #{ExternalSources}
# classes build and configure the downloader from scratch.
#
CACHE_ROOT = Pathname.new(File.join(ENV['HOME'], 'Library/Caches/CocoaPods'))
CACHE_ROOT.mkpath unless CACHE_ROOT.exist?
# @return [Fixnum] The maximum size for the cache expressed in Mb.
#
# @todo The {Installer::PodSourceInstaller} and the #{ExternalSources}
# classes build and configure the downloader from scratch.
#
MAX_CACHE_SIZE = 500
# @return [Pathname] The file to use a cache of the statistics provider.
#
STATISTICS_CACHE_FILE = CACHE_ROOT + 'statistics.yml'
autoload :Command, 'cocoapods/command'
autoload :Executable, 'cocoapods/executable'
autoload :ExternalSources, 'cocoapods/external_sources'
......
......@@ -48,7 +48,7 @@ module Pod
dates, groups = {}, {}
days.each {|d| dates[d] = Time.now - 60 * 60 * 24 * d}
sets = SourcesManager.all_sets
statistics_provider = Specification::Set::Statistics.new(STATISTICS_CACHE_FILE)
statistics_provider = Config.instance.spec_statistics_provider
creation_dates = statistics_provider.creation_dates(sets)
sets.each do |set|
......
......@@ -43,7 +43,7 @@ module Pod
sets.reject!{ |set| !set.specification.available_platforms.map(&:name).include?(:osx) }
end
statistics_provider = Specification::Set::Statistics.new(STATISTICS_CACHE_FILE)
statistics_provider = Config.instance.spec_statistics_provider
sets.each do |set|
begin
if @stats
......
......@@ -17,11 +17,14 @@ module Pod
:verbose => false,
:silent => false,
:skip_repo_update => false,
:aggressive_cache => false,
:clean => true,
:integrate_targets => true,
:new_version_message => true,
:cache_root => Pathname.new(File.join(ENV['HOME'], 'Library/Caches/CocoaPods')),
:max_cache_size => 500,
:aggressive_cache => false,
}
public
......@@ -68,6 +71,26 @@ module Pod
attr_accessor :skip_repo_update
alias_method :skip_repo_update?, :skip_repo_update
public
#-------------------------------------------------------------------------#
# @!group Cache
# @return [Fixnum] The maximum size for the cache expressed in Mb.
#
attr_accessor :max_cache_size
# @return [Pathname] The directory where CocoaPods should cache remote data
# and other expensive to compute information.
#
attr_accessor :cache_root
def cache_root
@cache_root.mkpath unless @cache_root.exist?
@cache_root
end
# Allows to set whether the downloader should use more aggressive caching
# options.
#
......@@ -80,7 +103,7 @@ module Pod
# options.
#
def aggressive_cache?
@aggressive_cache || (ENV['CP_AGGRESSIVE_CACHE'] != 'FALSE')
@aggressive_cache || (ENV['CP_AGGRESSIVE_CACHE'] == 'TRUE')
end
public
......@@ -193,6 +216,42 @@ module Pod
@lockfile_path ||= installation_root + 'Podfile.lock'
end
# @return [Pathname] The file to use a cache of the statistics provider.
#
def statistics_cache_file
cache_root + 'statistics.yml'
end
# @return [Pathname] The file to use to cache the search data.
#
def search_index_file
cache_root + 'search_index.yaml'
end
public
#-------------------------------------------------------------------------#
# @!group Dependency Injection
# @return [Downloader] The downloader to use for the retrieving remote
# source.
#
def downloader(target_path, options)
downloader = Downloader.for_target(target_path, options)
downloader.cache_root = cache_root
downloader.max_cache_size = max_cache_size
downloader.aggressive_cache = aggressive_cache?
downloader
end
# @return [Specification::Set::Statistics] The statistic provider to use
# for specifications.
#
def spec_statistics_provider
Specification::Set::Statistics.new(statistics_cache_file)
end
private
#-------------------------------------------------------------------------#
......
......@@ -136,10 +136,7 @@ module Pod
UI.titled_section("Pre-downloading: `#{name}` #{description}", { :verbose_prefix => "-> " }) do
target = sandbox.root + name
target.rmtree if target.exist?
downloader = Downloader.for_target(target, params)
downloader.cache_root = CACHE_ROOT.to_s
downloader.max_cache_size = MAX_CACHE_SIZE
downloader.aggressive_cache = false
downloader = Config.instance.downloader(target, params)
downloader.download
store_podspec(sandbox, target + "#{name}.podspec")
sandbox.store_pre_downloaded_pod(name)
......
......@@ -125,12 +125,7 @@ module Pod
# source.
#
def downloader
return @downloader if @downloader
@downloader = Downloader.for_target(root, root_spec.source.dup)
@downloader.cache_root = CACHE_ROOT.to_s
@downloader.max_cache_size = MAX_CACHE_SIZE
@downloader.aggressive_cache = aggressive_cache?
@downloader
@downloader ||= Config.instance.downloader(root, root_spec.source.dup)
end
#-----------------------------------------------------------------------#
......
......@@ -120,7 +120,7 @@ module Pod
# @return [Pathname] The path where the search index should be stored.
#
def search_index_path
CACHE_ROOT + 'search_index.yaml'
Config.instance.search_index_file
end
public
......
......@@ -113,6 +113,14 @@ module Pod
end
end
it "returns the statistics cache file" do
config.statistics_cache_file.to_s.should.end_with?('statistics.yml')
end
it "returns the search index file" do
config.search_index_file.to_s.should.end_with?('search_index.yaml')
end
end
#-------------------------------------------------------------------------#
......@@ -134,8 +142,43 @@ module Pod
it "cleans SCM dirs in dependency checkouts" do
config.should.clean
end
it "has a default cache size of 500" do
config.max_cache_size.should == 500
end
it "returns the cache root" do
config.cache_root.should == Pathname.new(File.join(ENV['HOME'], 'Library/Caches/CocoaPods'))
end
it "doesn't use aggressive cache" do
config.should.not.aggressive_cache?
end
end
#-------------------------------------------------------------------------#
describe "Dependency Injection" do
it "returns the downloader" do
downloader = config.downloader(Pathname.new(''), { :git => 'example.com' })
downloader.target_path.should == Pathname.new('')
downloader.url.should == 'example.com'
downloader.cache_root.should == config.cache_root
downloader.max_cache_size.should == 500
downloader.aggressive_cache.should.be.false
end
it "returns the specification statistics provider" do
stats_provider = config.spec_statistics_provider
stats_provider.cache_file.should == config.cache_root + 'statistics.yml'
end
end
#-------------------------------------------------------------------------#
describe "Private helpers" do
it "returns the path of the user settings file" do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment