Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file cache ttl #466

Merged
merged 2 commits into from Mar 23, 2020
Merged

file cache ttl #466

merged 2 commits into from Mar 23, 2020

Conversation

sveneld
Copy link

@sveneld sveneld commented Mar 22, 2020

Allow to configure file cache ttl in configuration file.

Type: feature
Issue: Fix #465
Breaking change: no

@sveneld sveneld force-pushed the feature-ttl branch 3 times, most recently from 1b5cf68 to 7dbd885 Compare March 22, 2020 12:58
@codecov-io
Copy link

codecov-io commented Mar 22, 2020

Codecov Report

Merging #466 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #466      +/-   ##
============================================
+ Coverage     86.51%   86.51%   +<.01%     
  Complexity     3158     3158              
============================================
  Files           204      204              
  Lines          8350     8353       +3     
============================================
+ Hits           7224     7227       +3     
  Misses         1126     1126
Impacted Files Coverage Δ Complexity Δ
...il/Cache/Driver/File/FileCacheGarbageCollector.php 89.65% <100%> (ø) 11 <1> (ø) ⬇️
.../php/PDepend/DependencyInjection/Configuration.php 94.87% <100%> (+0.13%) 4 <0> (ø) ⬇️
.../php/PDepend/Util/Cache/Driver/FileCacheDriver.php 100% <100%> (ø) 17 <2> (ø) ⬇️
...p/PDepend/DependencyInjection/PdependExtension.php 75% <100%> (+0.71%) 8 <0> (ø) ⬇️
src/main/php/PDepend/Util/Cache/CacheFactory.php 80% <100%> (+1.05%) 8 <4> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 09ff59f...260e07f. Read the comment docs.

Copy link
Member

@kylekatarnls kylekatarnls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approve this change but it would need the few adjustments mentioned below to be backward-compatible.

@@ -83,7 +83,8 @@ public function getConfigTreeBuilder()
->addDefaultsIfNotSet()
->children()
->enumNode('driver')->defaultValue($defaultCacheDriver)->values(array('file', 'memory'))->end()
->scalarNode('location')->defaultValue($home . '/.pdepend')->end()
->scalarNode('location')->info('This value is only used for the file cache.')->defaultValue($home . '/.pdepend')->end()
->integerNode('ttl')->info('This value is only used for the file cache. Value in seconds.')->defaultValue(30 * 24 * 60 *60)->end()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A space is missing in *60

*/
public function __construct($cacheDir, $maxDays = 30)
public function __construct($cacheDir, $ttl)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default value (30 * 86400) should be kept for backward compatibility as this is a public method. This means we should have a constant for 30 days in seconds so we don't duplicate it.

{
$this->cacheDir = $cacheDir;
$this->minTime = time() - ($maxDays * 86400);
$this->ttl = time() - $ttl;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ttl is a time-to-live (duration) but $this->ttl is actually an expiration timestamp (moment) so if we rename it, it should be more likely expirationTimestamp but not ttl.

* @param string $cacheKey Unique key for this cache instance.
*/
public function __construct($root, $cacheKey = null)
public function __construct($root, $ttl, $cacheKey = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we should also have a default value. The easiest way is to put it everywhere $ttl is added.

@@ -72,6 +79,7 @@ protected function setUp()
parent::setUp();

$this->cacheDir = $this->createRunResourceURI('cache') . '/';
$this->cacheTtl = 24 * 60 * 60 * 30;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather have ordered numbers from biggest unit to the smallest one.

@@ -72,16 +79,17 @@ protected function setUp()
parent::setUp();

$this->cacheDir = $this->createRunResourceURI('cache');
$this->cacheTtl = 24*60*60*30;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add spaces (it could also use a common constant).

@kylekatarnls kylekatarnls added this to the 2.7.2 milestone Mar 22, 2020
@sveneld
Copy link
Author

sveneld commented Mar 22, 2020

I approve this change but it would need the few adjustments mentioned below to be backward-compatible.

i made changes

Copy link
Member

@kylekatarnls kylekatarnls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@sveneld
Copy link
Author

sveneld commented Mar 22, 2020

Thanks!

mayby you can add this changes to 2.7.1?

@kylekatarnls
Copy link
Member

No I can't, 2.7.1 is already released: https://github.com/pdepend/pdepend/releases/tag/2.7.1

@sveneld
Copy link
Author

sveneld commented Mar 22, 2020

when 2.7.2 tag will be released?

@kylekatarnls
Copy link
Member

kylekatarnls commented Mar 22, 2020

If it last too many weeks to handle other issues planned for 2.7.2, we will release an intermediate version and postpone remaining tasks to 2.7.3. But meanwhile you can:

composer require pdepend/pdepend:dev-master

To test the master branch when this PR will receive a second approval and be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

file cache ttl
5 participants