Skip to content

Commit d924dac

Browse files
authored
Merge pull request #3 from duckdev/dev
Syncing dev
2 parents 6968cd7 + e59c997 commit d924dac

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/services/class-addon.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,23 @@ class Addon extends Service {
2727
*
2828
* @since 1.0.0
2929
*
30+
* @param bool $force Should force update cache.
31+
*
3032
* @return array
3133
*/
32-
public function get_addons(): array {
34+
public function get_addons( bool $force = false ): array {
3335
// Only if current plugin has addons.
34-
if ( $this->plugin->has_addons() ) {
36+
if ( ! $this->plugin->has_addons() ) {
3537
return array();
3638
}
3739

3840
// Get from cache first.
39-
$addons = $this->get_transient( 'addons' );
40-
// If found is cache, return it.
41-
if ( false !== $addons ) {
42-
return $addons;
41+
if ( ! $force ) {
42+
$addons = $this->get_transient( 'addons' );
43+
// If found is cache, return it.
44+
if ( false !== $addons ) {
45+
return $addons;
46+
}
4347
}
4448

4549
// Get from the API.
@@ -49,7 +53,7 @@ public function get_addons(): array {
4953
// Format the data.
5054
$addons = array_map( array( $this, 'format_addon_data' ), $addons );
5155
// Save to cache.
52-
$this->set_transient( 'addons', $addons );
56+
$this->set_transient( 'addons', $addons, DAY_IN_SECONDS );
5357

5458
return $addons;
5559
}

0 commit comments

Comments
 (0)