Last active
December 20, 2015 00:28
-
-
Save ssimeonov/6041586 to your computer and use it in GitHub Desktop.
ActiveSupport::Cache::MemoryStore does not count the length of keys as it computes its size. This can lead to much more memory than expected being consumed, especially in the case where the keys are big (URLs, IP addresses, etc.) and the values are small, e.g., integers or booleans. In the example below a cache of size 100 bytes adds two entries…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2.0.0p247 :034 > cache = ActiveSupport::Cache.lookup_store :memory_store, size: 100 | |
=> <#ActiveSupport::Cache::MemoryStore entries=0, size=0, options={:size=>100}> | |
2.0.0p247 :035 > key_prefix = '*' * 50 | |
=> "**************************************************" | |
2.0.0p247 :036 > cache.fetch("#{key_prefix}-1") { 0 } | |
=> 0 | |
2.0.0p247 :037 > cache.fetch("#{key_prefix}-2") { 0 } | |
=> 0 | |
2.0.0p247 :038 > cache | |
=> <#ActiveSupport::Cache::MemoryStore entries=2, size=8, options={:size=>100}> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment