sorentwo / readthis

:newspaper: Pooled active support compliant caching with redis
MIT License
506 stars 40 forks source link

Skip the provided block at fetch method if write nil value. #50

Closed satoruk closed 8 years ago

satoruk commented 8 years ago

This PR is to skip the provided block in fetch method if write nil value. The behavior same as ActiveSupport::Cache::MemoryStore.

cache.write('short-key', nil)
result = cache.fetch('short-key') { 'skip this block' } # => expect nil
coveralls commented 8 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling dd07e18b546d817cd2b747d993a5c693bf1c500c on satoruk:feature/skip_write_in_fetch_if_exist into 654fc11e6772bd07a0d5a9d8338e56cd7f0f2f54 on sorentwo:master.

coveralls commented 8 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling e6aeccce85eb2d10da7d1c49f20dc94f876e8625 on satoruk:feature/skip_write_in_fetch_if_exist into 654fc11e6772bd07a0d5a9d8338e56cd7f0f2f54 on sorentwo:master.

sorentwo commented 8 years ago

This difference is intentional, as noted in the README:

Like other ActiveSupport::Cache implementations it is possible to cache nil as a value. However, the fetch methods treat nil values as a cache miss and re-generate/re-cache the value. Caching nil isn't recommended.

satoruk commented 8 years ago

Oops, Sorry 😭