| @@ -1,0 +1,35 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace NotificationX\Core; | |
| 4 | + | |
| 5 | +use NotificationX\Admin\Entries; | |
| 6 | +use NotificationX\Admin\Settings; | |
| 7 | +use NotificationX\Core\Database; | |
| 8 | +use NotificationX\GetInstance; | |
| 9 | + | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * @method static Limiter get_instance($args = null) | |
| 13 | + */ | |
| 14 | +class Limiter { | |
| 15 | + use GetInstance; | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * Initial Invoked | |
| 19 | + */ | |
| 20 | + public function __construct() { | |
| 21 | + } | |
| 22 | + | |
| 23 | + public function remove($nx_id, $new) { | |
| 24 | + $count = Entries::get_instance()->count($nx_id, 'nx_id'); | |
| 25 | + $limit = Settings::get_instance()->get('settings.cache_limit', 100); | |
| 26 | + if ($limit <= 0) { | |
| 27 | + $limit = 100; | |
| 28 | + } | |
| 29 | + | |
| 30 | + if ($new + $count > $limit) { | |
| 31 | + $overflow = ($new + $count) - $limit; | |
| 32 | + Entries::get_instance()->delete_entries($nx_id, $overflow); | |
| 33 | + } | |
| 34 | + } | |
| 35 | +} | |