diff --git a/app/models/project.rb b/app/models/project.rb
index a667857d058dab6f5049e1bdcbed477d0adbaf46..d306f86f783d80a1e211e1c616f643ab2f9376cb 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -378,6 +378,12 @@ class Project < ActiveRecord::Base
 
       joins(join_body).reorder('join_note_counts.amount DESC')
     end
+
+    def cached_count
+      Rails.cache.fetch('total_project_count', expires_in: 5.minutes) do
+        Project.count
+      end
+    end
   end
 
   def repository_storage_path
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 1c3d694075af2e12ec3101d77db2e9f5f3466ac7..9c3b4712cab653e0ab4e1087fc17dc5d9315b64c 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -714,6 +714,20 @@ describe Project, models: true do
     it { expect(project.builds_enabled?).to be_truthy }
   end
 
+  describe '.cached_count', caching: true do
+    let(:group)     { create(:group, :public) }
+    let!(:project1) { create(:empty_project, :public, group: group) }
+    let!(:project2) { create(:empty_project, :public, group: group) }
+
+    it 'returns total project count' do
+      expect(Project).to receive(:count).once.and_call_original
+
+      3.times do
+        expect(Project.cached_count).to eq(2)
+      end
+    end
+  end
+
   describe '.trending' do
     let(:group)    { create(:group, :public) }
     let(:project1) { create(:empty_project, :public, group: group) }
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 4f3aacf55be9dbe4740f5c28e5f5dff58c2ce0b0..2e2aa7c4fc04e7681ce6d37d50a0055b23e4064a 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -42,6 +42,13 @@ RSpec.configure do |config|
   config.before(:suite) do
     TestEnv.init
   end
+
+  config.around(:each, :caching) do |example|
+    caching_store = Rails.cache
+    Rails.cache = ActiveSupport::Cache::MemoryStore.new if example.metadata[:caching]
+    example.run
+    Rails.cache = caching_store
+  end
 end
 
 FactoryGirl::SyntaxRunner.class_eval do