diff --git a/lib/amee/connection.rb b/lib/amee/connection.rb
index <HASH>..<HASH> 100644
--- a/lib/amee/connection.rb
+++ b/lib/amee/connection.rb
@@ -298,7 +298,8 @@ module AMEE
     def cache_key(path)
       # We have to make sure cache keys don't get too long for the filesystem,
       # so we cut them off if they're too long and add a digest for uniqueness.
-      newpath = (path.length < 255) ? path : path.first(192)+Digest::MD5.hexdigest(path)
+      newpath = path.gsub(/[^0-9a-z\/]/i, '')
+      newpath = (newpath.length < 255) ? newpath : newpath.first(192)+Digest::MD5.hexdigest(newpath)
       (@server+newpath)
     end
 
diff --git a/spec/cache_spec.rb b/spec/cache_spec.rb
index <HASH>..<HASH> 100644
--- a/spec/cache_spec.rb
+++ b/spec/cache_spec.rb
@@ -75,6 +75,11 @@ describe AMEE::Connection do
       c.expire_cache
       i = c.item :label => 'biodiesel'
     end
+    
+    it "removes special characters from cache keys" do
+      setup_connection
+      @connection.send(:cache_key, "/%cache/$4/%20test").should eql 'server.example.com/cache/4/20test'
+    end
 
     describe 'and automatic invalidation' do
Remove special chars from cache keys for Rails 3 compatibility. SDK-<I>