キャッシュシステム (#26) +一部修正

諏訪子 <suwako@076.moe>、2026-04-30 19:50
コミット cf8545c5d89a082181ede6b6d1a0e220fdb9170e ・親 d3e04ac ・ファイルを見る

5個のファイル、+275 -217

@@ -99,6 +99,7 @@
9999 $tmpl->assign('data', $data->data);
100100
101101 $tmpl->addCss('table');
102+ $tmpl->addCss('openprovider');
102103 $tmpl->render('listcustomers');
103104 exit();
104105
@@ -115,7 +116,11 @@
115116 'additional_data' => [
116117 'company_registration_number' => $_POST['company_registration_number'] ?? '',
117118 'company_url' => $_POST['company_url'] ?? '',
118- 'birth_date' => $_POST['birth_year'] !== '' && $_POST['birth_month'] !== '' && $_POST['birth_day'] !== '' ? $_POST['birth_year'].'-'.$_POST['birth_month'].'-'.$_POST['birth_day'] : '',
119+ 'birth_date' => (isset($_POST['birth_year']) && $_POST['birth_year'] !== '')
120+ && (isset($_POST['birth_month']) && $_POST['birth_month'] !== '')
121+ && (isset($_POST['birth_day']) && $_POST['birth_day'] !== '')
122+ ? $_POST['birth_year'].'-'.$_POST['birth_month'].'-'.$_POST['birth_day']
123+ : '',
119124 'trading_name' => $_POST['company_name'] ?? '',
120125 ],
121126 'address' => [
@@ -142,7 +147,10 @@
142147 'locale' => 'ja_JP',
143148 'name' => [
144149 'first_name' => $_POST['first_name'] ?? '',
145- 'full_name' => $_POST['first_name'] !== '' && $_POST['last_name'] !== '' ? $_POST['first_name'].' '.$_POST['last_name'] : '',
150+ 'full_name' => (isset($_POST['first_name']) && $_POST['first_name'] !== '')
151+ && (isset($_POST['last_name']) && $_POST['last_name'] !== '')
152+ ? $_POST['first_name'].' '.$_POST['last_name']
153+ : '',
146154 'last_name' => $_POST['last_name'] ?? '',
147155 ],
148156 'phone' => [
@@ -0,0 +1,118 @@
1+<?php
2+/*************************************************************
3+# 076 License
4+
5+Copyright (c) テクニカル諏訪子
6+
7+Permission is hereby granted to any person obtaining a copy of the software
8+Little Beast (the "Software") to use, modify, merge, copy, publish, distribute,
9+sublicense, and/or sell copies of the Software, subject to the following conditions:
10+
11+ 1. **Origin Attribution**:
12+ - You must not misrepresent the origin of the Software; you must not claim
13+ you created the original Software.
14+ - If the Software is used in a product, you must either:
15+ a. Provide clear attribution in the product's documentation, user interface,
16+ or other visible areas, **OR**
17+ b. Pay the original developers a fee they specify in writing.
18+ 2. **Usage Restriction**:
19+ - The Software, or any derivative works, dependencies, or libraries
20+ incorporating it, must not be used for censorship or to suppress freedom of
21+ speech, expression, or creativity. Prohibited uses include, but are not
22+ limited to:
23+ - Censorship of so-called "hate speech", visuals, non-mainstream opinions,
24+ ideas, or objective reality.
25+ - Tools or systems designed to restrict access to information or
26+ artistic works.
27+ 3. **Notice Preservation**:
28+ - This license and the above copyright notice must remain intact in all copies
29+ of the source code.
30+
31+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
32+INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
33+PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
34+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
35+CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
36+OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37+ */
38+namespace Std\Lib;
39+
40+use Result;
41+
42+/**
43+ * キャッシュ
44+ */
45+class Cache {
46+ private string $dataDir;
47+ protected int $dataDuration = 1800; // 30分
48+
49+ public function __construct(string $dataDir) {
50+ $this->dataDir = $dataDir;
51+ }
52+
53+ /**
54+ * キャッシュの作成
55+ *
56+ * @param string $type キャッシュ類(例:login、domainlist等)
57+ * @param array $data 保存するデータ
58+ * @return Result
59+ */
60+ public function set(string $type, array $data): Result {
61+ if (!file_exists($this->dataDir)) {
62+ if (!mkdir($this->dataDir, 0755))
63+ return Result::Error('エラー:ユーザーのアイコンディレクトリの作成に失敗。');
64+ }
65+
66+ $data['lifespan'] = time();
67+ $json = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
68+ if (file_put_contents("{$this->dataDir}{$type}.json", $json) === false) return Result::Error('エラー:ユーザーデータの保存に失敗。');
69+
70+ return Result::Success();
71+ }
72+
73+ /**
74+ * キャッシュから受け取り
75+ *
76+ * @param string $type キャッシュ類(例:login、domainlist等)
77+ * @return array
78+ */
79+ public function get(string $type): array {
80+ if (!file_exists("{$this->dataDir}{$type}.json")) return [];
81+
82+ $content = file_get_contents("{$this->dataDir}{$type}.json");
83+ if ($content === false) return [];
84+
85+ $data = json_decode($content, true);
86+ if (json_last_error() !== JSON_ERROR_NONE || !is_array($data)) return [];
87+
88+ return $data;
89+ }
90+
91+ /**
92+ * キャッシュを破壊する
93+ *
94+ * @param string $name キャッシュのファイル名
95+ * @return Result
96+ */
97+ public function murder(string $name): Result {
98+ if (!file_exists("{$this->dataDir}{$name}.json")) return Result::Error('キャッシュファイルが存在しない。');
99+ if (!unlink("{$this->dataDir}{$name}.json")) return Result::Error('キャッシュファイルの削除に失敗。');
100+ return Result::Success();
101+ }
102+
103+ /**
104+ * キャッシュ有効期限の確認
105+ *
106+ * @param array $cache
107+ * @param mixed $data デフォルト=null
108+ * @param string $dataPoint デフォルト=query
109+ * @return bool
110+ */
111+ public function validate(array $cache, mixed $data = null, string $dataPoint = 'query'): bool {
112+ if (NULL === $data) return (!empty($cache) && (isset($cache['lifespan']) && time() < ($cache['lifespan'] + $this->dataDuration)));
113+ else return (!empty($cache)
114+ && (isset($cache[$dataPoint])
115+ && $cache[$dataPoint] === $data)
116+ && (isset($cache['lifespan']) && time() < ($cache['lifespan'] + $this->dataDuration)));
117+ }
118+}
@@ -37,14 +37,15 @@
3737 */
3838 namespace Std\Lib;
3939
40+use Std\Lib\Cache;
4041 use Std\Lib\Curl;
4142 use Result;
4243
4344 class Openprovider {
44- protected string $dataDir = ROOT."/data/cache/openprovider/";
45+ protected string $cacheDir = ROOT."/data/cache/openprovider/";
4546 protected int $tokenDuration = 172800; // 48時間
46- protected int $dataDuration = 1800; // 30分
4747
48+ private Cache $cache;
4849 private string $user = '';
4950 private string $pass = '';
5051 private string $token = '';
@@ -59,6 +60,7 @@
5960 $this->user = OPENPROVIDER['username'];
6061 $this->pass = OPENPROVIDER['password'];
6162 $this->ip = OPENPROVIDER['ip'];
63+ $this->cache = new Cache($this->cacheDir);
6264 }
6365
6466 /**
@@ -70,7 +72,7 @@
7072 public function login(): Result {
7173 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
7274 $cacheName = 'login';
73- $cache = $this->getCache($cacheName);
75+ $cache = $this->cache->get($cacheName);
7476 if (time() < ($this->lastAuth + $this->tokenDuration)) {
7577 $this->token = $cache['data']['token'];
7678 $this->lastAuth = $cache['last_auth'];
@@ -110,7 +112,7 @@
110112 $this->token = $res['data']['token'];
111113 $this->lastAuth = time();
112114 $res['last_auth'] = $this->lastAuth;
113- $this->setCache($cacheName, $res);
115+ $this->cache->set($cacheName, $res);
114116
115117 return Result::Success('', $res);
116118 }
@@ -150,14 +152,14 @@
150152 */
151153 public function listDomains(array $query = []): Result {
152154 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
153- $cacheName = 'listdomains'
154- $cache = $this->getCache($cacheName);
155- if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
155+ $cacheName = 'listdomains';
156+ $cache = $this->cache->get($cacheName);
157+ if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
156158
157159 $curl = $this->setupCurl('/domains');
158160 $res = $this->curlResult($curl);
159161 if (isset($res['data']['results'])) {
160- $this->setCache($cacheName, $res->data);
162+ $this->cache->set($cacheName, $res->data);
161163 return Result::Success('', $res['data']['results']);
162164 }
163165
@@ -271,14 +273,14 @@
271273 if (isset($query['domain.extension'])) $ext = $query['domain.extension'];
272274 $cacheName = $name && $ext ? "domainadditionaldata-{$name}.{$ext}" : 'domainadditionaldata';
273275
274- $cache = $this->getCache($cacheName);
275- if ($this->isValidLifespan($cache)) return Result::Success('', $cache);
276+ $cache = $this->cache->get($cacheName);
277+ if ($this->cache->validate($cache)) return Result::Success('', $cache);
276278
277279 $uri = "/domains/additional-data?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
278280 $curl = $this->setupCurl($uri);
279281 $res = $this->curlResult($curl);
280282 if (isset($res->data['data'])) {
281- $this->setCache($cacheName, $res->data);
283+ $this->cache->set($cacheName, $res->data);
282284 return Result::Success('', $res->data);
283285 }
284286
@@ -302,14 +304,14 @@
302304 if (isset($query['domain.extension'])) $ext = $query['domain.extension'];
303305 $cacheName = $name && $ext ? "domainadditionaldata-{$name}.{$ext}" : 'domainadditionaldata';
304306
305- $cache = $this->getCache($cacheName);
306- if ($this->isValidLifespan($cache)) return Result::Success('', $cache);
307+ $cache = $this->cache->get($cacheName);
308+ if ($this->cache->validate($cache)) return Result::Success('', $cache);
307309
308310 $uri = "/domains/additional-data/customers?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
309311 $curl = $this->setupCurl($uri);
310312 $res = $this->curlResult($curl);
311313 if (isset($res->data['data'])) {
312- $this->setCache($cacheName, $res->data);
314+ $this->cache->set($cacheName, $res->data);
313315 return Result::Success('', $res->data);
314316 }
315317
@@ -333,14 +335,14 @@
333335 if (isset($query['domain.extension'])) $ext = $query['domain.extension'];
334336 $cacheName = $name && $ext ? "domainprices-{$name}.{$ext}" : 'domainprices';
335337
336- $cache = $this->getCache($cacheName);
337- if ($this->isValidLifespan($cache)) return Result::Success('', $cache);
338+ $cache = $this->cache->get($cacheName);
339+ if ($this->cache->validate($cache)) return Result::Success('', $cache);
338340
339341 $uri = "/domains/prices?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
340342 $curl = $this->setupCurl($uri);
341343 $res = $this->curlResult($curl);
342344 if (isset($res->data['data'])) {
343- $this->setCache($cacheName, $res->data);
345+ $this->cache->set($cacheName, $res->data);
344346 return Result::Success('', $res->data);
345347 }
346348
@@ -403,8 +405,8 @@
403405 public function listTlds(array $query = []): Result {
404406 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
405407 $cacheName = 'listtlds';
406- $cache = $this->getCache($cacheName);
407- if ($this->isValidLifespan($cache)) return Result::Success('', $cache);
408+ $cache = $this->cache->get($cacheName);
409+ if ($this->cache->validate($cache)) return Result::Success('', $cache);
408410
409411 if (empty($query)) $query = [ 'limit' => 10, 'offset' => 0, 'order' => 'ASC' ];
410412 foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
@@ -413,7 +415,7 @@
413415 $curl = $this->setupCurl($uri);
414416 $res = $this->curlResult($curl);
415417 if (isset($res->data['data'])) {
416- $this->setCache($cacheName, $res->data);
418+ $this->cache->set($cacheName, $res->data);
417419 return Result::Success('', $res->data);
418420 }
419421
@@ -430,8 +432,8 @@
430432 public function getTld(string $tld, array $query = []): Result {
431433 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
432434 $cacheName = "gettld-{$tld}";
433- $cache = $this->getCache($cacheName);
434- if ($this->isValidLifespan($cache)) return Result::Success('', $cache);
435+ $cache = $this->cache->get($cacheName);
436+ if ($this->cache->validate($cache)) return Result::Success('', $cache);
435437
436438 if (empty($query)) $query = [ 'limit' => 10, 'offset' => 0 ];
437439 foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
@@ -440,7 +442,7 @@
440442 $curl = $this->setupCurl($uri);
441443 $res = $this->curlResult($curl);
442444 if (isset($res->data['data'])) {
443- $this->setCache($cacheName, $res->data);
445+ $this->cache->set($cacheName, $res->data);
444446 return Result::Success('', $res->data);
445447 }
446448
@@ -460,8 +462,8 @@
460462 public function listInvoices(array $query = []): Result {
461463 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
462464 $cacheName = 'listinvoices';
463- $cache = $this->getCache($cacheName);
464- if ($this->isValidLifespan($cache)) return Result::Success('', $cache);
465+ $cache = $this->cache->get($cacheName);
466+ if ($this->cache->validate($cache)) return Result::Success('', $cache);
465467
466468 if (empty($query)) $query = [ 'limit' => 10, 'offset' => 0 ];
467469 foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
@@ -470,7 +472,7 @@
470472 $curl = $this->setupCurl($uri);
471473 $res = $this->curlResult($curl);
472474 if (isset($res->data['data'])) {
473- $this->setCache($cacheName, $res->data);
475+ $this->cache->set($cacheName, $res->data);
474476 return Result::Success('', $res->data);
475477 }
476478
@@ -489,8 +491,8 @@
489491 public function listPayments(array $query = []): Result {
490492 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
491493 $cacheName = 'listpayments';
492- $cache = $this->getCache($cacheName);
493- if ($this->isValidLifespan($cache)) return Result::Success('', $cache);
494+ $cache = $this->cache->get($cacheName);
495+ if ($this->cache->validate($cache)) return Result::Success('', $cache);
494496
495497 if (empty($query)) $query = [ 'limit' => 10, 'offset' => 0 ];
496498 foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
@@ -499,7 +501,7 @@
499501 $curl = $this->setupCurl($uri);
500502 $res = $this->curlResult($curl);
501503 if (isset($res->data['data'])) {
502- $this->setCache($cacheName, $res->data);
504+ $this->cache->set($cacheName, $res->data);
503505 return Result::Success('', $res->data);
504506 }
505507
@@ -518,8 +520,8 @@
518520 public function listTransactions(array $query = []): Result {
519521 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
520522 $cacheName = 'listtransactions';
521- $cache = $this->getCache($cacheName);
522- if ($this->isValidLifespan($cache)) return Result::Success('', $cache);
523+ $cache = $this->cache->get($cacheName);
524+ if ($this->cache->validate($cache)) return Result::Success('', $cache);
523525
524526 if (empty($query)) $query = [ 'limit' => 10, 'offset' => 0 ];
525527 foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
@@ -528,7 +530,7 @@
528530 $curl = $this->setupCurl($uri);
529531 $res = $this->curlResult($curl);
530532 if (isset($res->data['data'])) {
531- $this->setCache($cacheName, $res->data);
533+ $this->cache->set($cacheName, $res->data);
532534 return Result::Success('', $res->data);
533535 }
534536
@@ -570,8 +572,8 @@
570572 public function listNameservers(array $query = []): Result {
571573 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
572574 $cacheName = 'listnameservers';
573- $cache = $this->getCache($cacheName);
574- if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
575+ $cache = $this->cache->get($cacheName);
576+ if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
575577
576578 if (empty($query)) $query = [ 'limit' => 25, 'offset' => 0, 'order_by.name' => 'asc' ];
577579 foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
@@ -580,7 +582,7 @@
580582 $curl = $this->setupCurl($uri);
581583 $res = $this->curlResult($curl);
582584 if (isset($res->data['data'])) {
583- $this->setCache($cacheName, $res->data);
585+ $this->cache->set($cacheName, $res->data);
584586 return Result::Success('', $res->data);
585587 }
586588
@@ -601,7 +603,7 @@
601603 $curl = $this->setupCurl($uri, 'POST', $payload);
602604 $res = $this->curlResult($curl);
603605 if (isset($res->data['data'])) {
604- $this->murderCache('listnameservers');
606+ $this->cache->murder('listnameservers');
605607 return Result::Success('ネームサーバーの追加に成功。', $res->data);
606608 }
607609
@@ -619,8 +621,8 @@
619621 public function getNameserver(string $domain, array $query = []): Result {
620622 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
621623 $cacheName = "listnameserver-{$domain}";
622- $cache = $this->getCache($cacheName);
623- if ($this->isValidLifespan($cache)) return Result::Success('', $cache);
624+ $cache = $this->cache->get($cacheName);
625+ if ($this->cache->validate($cache)) return Result::Success('', $cache);
624626
625627 if (empty($query)) $query = [ 'limit' => 100, 'offset' => 0, 'order_by.name' => 'asc' ];
626628 foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
@@ -629,7 +631,7 @@
629631 $curl = $this->setupCurl($uri);
630632 $res = $this->curlResult($curl);
631633 if (isset($res->data['data'])) {
632- $this->setCache($cacheName, $res->data);
634+ $this->cache->set($cacheName, $res->data);
633635 return Result::Success('', $res->data);
634636 }
635637
@@ -651,8 +653,8 @@
651653 $curl = $this->setupCurl($uri, 'PUT', $payload);
652654 $res = $this->curlResult($curl);
653655 if (isset($res->data['data'])) {
654- $this->murderCache('listnameservers');
655- $this->murderCache("listnameserver-{$domain}");
656+ $this->cache->murder('listnameservers');
657+ $this->cache->murder("listnameserver-{$domain}");
656658 if ($res->data['data']['success']) return Result::Success('ネームサーバーの更新に成功。', $res->data);
657659 }
658660
@@ -673,8 +675,8 @@
673675 $curl = $this->setupCurl($uri, 'DELETE');
674676 $res = $this->curlResult($curl);
675677 if (isset($res->data['data'])) {
676- $this->murderCache('listnameservers');
677- $this->murderCache("listnameserver-{$domain}");
678+ $this->cache->murder('listnameservers');
679+ $this->cache->murder("listnameserver-{$domain}");
678680 if ($res->data['data']['success']) return Result::Success('ネームサーバーの削除に成功。', $res->data);
679681 }
680682
@@ -693,8 +695,8 @@
693695 public function listNsGroups(array $query = []): Result {
694696 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
695697 $cacheName = 'listnsgroups';
696- $cache = $this->getCache($cacheName);
697- if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
698+ $cache = $this->cache->get($cacheName);
699+ if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
698700
699701 if (empty($query)) $query = [ 'limit' => 25, 'offset' => 0, 'order_by.name' => 'asc' ];
700702 foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
@@ -703,7 +705,7 @@
703705 $curl = $this->setupCurl($uri);
704706 $res = $this->curlResult($curl);
705707 if (isset($res->data['data'])) {
706- $this->setCache($cacheName, $res->data);
708+ $this->cache->set($cacheName, $res->data);
707709 return Result::Success('', $res->data);
708710 }
709711
@@ -724,7 +726,7 @@
724726 $curl = $this->setupCurl($uri, 'POST', $payload);
725727 $res = $this->curlResult($curl);
726728 if (isset($res->data['data'])) {
727- $this->murderCache('listnsgroups');
729+ $this->cache->murder('listnsgroups');
728730 return Result::Success('NSグループの追加に成功。', $res->data);
729731 }
730732
@@ -742,8 +744,8 @@
742744 public function getNsGroup(string $nsGroup, array $query = []): Result {
743745 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
744746 $cacheName = "listnsgroup-{$nsGroup}";
745- $cache = $this->getCache($cacheName);
746- if ($this->isValidLifespan($cache)) return Result::Success('', $cache);
747+ $cache = $this->cache->get($cacheName);
748+ if ($this->cache->validate($cache)) return Result::Success('', $cache);
747749
748750 if (empty($query)) $query = [ 'limit' => 100, 'offset' => 0, 'order_by.name' => 'asc' ];
749751 foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
@@ -752,7 +754,7 @@
752754 $curl = $this->setupCurl($uri);
753755 $res = $this->curlResult($curl);
754756 if (isset($res->data['data'])) {
755- $this->setCache($cacheName, $res->data);
757+ $this->cache->set($cacheName, $res->data);
756758 return Result::Success('', $res->data);
757759 }
758760
@@ -774,8 +776,8 @@
774776 $curl = $this->setupCurl($uri, 'PUT', $payload);
775777 $res = $this->curlResult($curl);
776778 if (isset($res->data['data'])) {
777- $this->murderCache('listnsgroups');
778- $this->murderCache("listnsgroup-{$nsGroup}");
779+ $this->cache->murder('listnsgroups');
780+ $this->cache->murder("listnsgroup-{$nsGroup}");
779781 if ($res->data['data']['success']) return Result::Success('NSグループの更新に成功。', $res->data);
780782 }
781783
@@ -796,8 +798,8 @@
796798 $curl = $this->setupCurl($uri, 'DELETE');
797799 $res = $this->curlResult($curl);
798800 if (isset($res->data['data'])) {
799- $this->murderCache('listnsgroups');
800- $this->murderCache("listnsgroup-{$nsGroup}");
801+ $this->cache->murder('listnsgroups');
802+ $this->cache->murder("listnsgroup-{$nsGroup}");
801803 if ($res->data['data']['success']) return Result::Success('NSグループの削除に成功。', $res->data);
802804 }
803805
@@ -816,8 +818,8 @@
816818 public function listDnsTemplate(array $query = []): Result {
817819 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
818820 $cacheName = 'listdnstemplates';
819- $cache = $this->getCache($cacheName);
820- if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
821+ $cache = $this->cache->get($cacheName);
822+ if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
821823
822824 foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
823825 $uri = '/dns/templates?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
@@ -825,7 +827,7 @@
825827 $res = $this->curlResult($curl);
826828 if (isset($res->data['data'])) {
827829 $res->data['query'] = $query;
828- $this->setCache($cacheName, $res->data);
830+ $this->cache->set($cacheName, $res->data);
829831 return Result::Success('', $res->data);
830832 }
831833
@@ -846,7 +848,7 @@
846848 $curl = $this->setupCurl($uri, 'POST', $payload);
847849 $res = $this->curlResult($curl);
848850 if (isset($res->data['data'])) {
849- $this->murderCache('listdnstemplates');
851+ $this->cache->murder('listdnstemplates');
850852 return Result::Success('DNSテンプレートの追加に成功。', $res->data);
851853 }
852854
@@ -863,14 +865,14 @@
863865 public function getDnsTemplate(int $id): Result {
864866 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
865867 $cacheName = "getdnstemplate-{$id}";
866- $cache = $this->getCache($cacheName);
867- if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
868+ $cache = $this->cache->get($cacheName);
869+ if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
868870
869871 $uri = "/dns/templates/{$id}";
870872 $curl = $this->setupCurl($uri);
871873 $res = $this->curlResult($curl);
872874 if (isset($res->data['data'])) {
873- $this->setCache($cacheName, $res->data);
875+ $this->cache->set($cacheName, $res->data);
874876 return Result::Success('', $res->data);
875877 }
876878
@@ -891,8 +893,8 @@
891893 $curl = $this->setupCurl($uri, 'DELETE');
892894 $res = $this->curlResult($curl);
893895 if (isset($res->data['data'])) {
894- $this->murderCache('listdnstemplates');
895- $this->murderCache("getdnstemplate-{$id}");
896+ $this->cache->murder('listdnstemplates');
897+ $this->cache->murder("getdnstemplate-{$id}");
896898 if ($res->data['data']['success']) return Result::Success('DNSテンプレートの削除に成功。', $res->data);
897899 }
898900
@@ -910,8 +912,8 @@
910912 public function listDnsZones(array $query = []): Result {
911913 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
912914 $cacheName = 'listdnszones';
913- $cache = $this->getCache($cacheName);
914- if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
915+ $cache = $this->cache->get($cacheName);
916+ if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
915917
916918 if (empty($query)) $query = [ 'limit' => 25, 'offset' => 0, 'order_by.name' => 'asc' ];
917919 foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
@@ -920,7 +922,7 @@
920922 $curl = $this->setupCurl($uri);
921923 $res = $this->curlResult($curl);
922924 if (isset($res->data['data'])) {
923- $this->setCache($cacheName, $res->data);
925+ $this->cache->set($cacheName, $res->data);
924926 return Result::Success('', $res->data);
925927 }
926928
@@ -941,7 +943,7 @@
941943 $curl = $this->setupCurl($uri, 'POST', $payload);
942944 $res = $this->curlResult($curl);
943945 if (isset($res->data['data'])) {
944- $this->murderCache('listdnszones');
946+ $this->cache->murder('listdnszones');
945947 return Result::Success('DNSゾーンの追加に成功。', $res->data);
946948 }
947949
@@ -958,8 +960,8 @@
958960 public function getDnsZone(string $domain, array $query = []): Result {
959961 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
960962 $cacheName = "getdnszone-{$domain}";
961- $cache = $this->getCache($cacheName);
962- if ($this->isValidLifespan($cache)) return Result::Success('', $cache);
963+ $cache = $this->cache->get($cacheName);
964+ if ($this->cache->validate($cache)) return Result::Success('', $cache);
963965
964966 if (empty($query)) $query = [ 'limit' => 100, 'offset' => 0, 'order_by.name' => 'asc' ];
965967 foreach ($query as $k => $v) if (is_bool($v)) $query[$k] = $v ? 'true' : 'false';
@@ -968,7 +970,7 @@
968970 $curl = $this->setupCurl($uri);
969971 $res = $this->curlResult($curl);
970972 if (isset($res->data['data'])) {
971- $this->setCache($cacheName, $res->data);
973+ $this->cache->set($cacheName, $res->data);
972974 return Result::Success('', $res->data);
973975 }
974976
@@ -990,8 +992,8 @@
990992 $curl = $this->setupCurl($uri, 'PUT', $payload);
991993 $res = $this->curlResult($curl);
992994 if (isset($res->data['data'])) {
993- $this->murderCache('listdnszones');
994- $this->murderCache("getdnszone-{$domain}");
995+ $this->cache->murder('listdnszones');
996+ $this->cache->murder("getdnszone-{$domain}");
995997 if ($res->data['data']['success']) return Result::Success('DNSゾーンの更新に成功。', $res->data);
996998 }
997999
@@ -1012,8 +1014,8 @@
10121014 $curl = $this->setupCurl($uri, 'DELETE');
10131015 $res = $this->curlResult($curl);
10141016 if (isset($res->data['data'])) {
1015- $this->murderCache('listdnszones');
1016- $this->murderCache("getdnszone-{$domain}");
1017+ $this->cache->murder('listdnszones');
1018+ $this->cache->murder("getdnszone-{$domain}");
10171019 if ($res->data['data']['success']) return Result::Success('DNSゾーンの削除に成功。', $res->data);
10181020 }
10191021
@@ -1031,13 +1033,13 @@
10311033 public function listZoneRecords(string $domain): Result {
10321034 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
10331035 $cacheName = "getzonerecords-{$domain}";
1034- $cache = $this->getCache($cacheName);
1035- if ($this->isValidLifespan($cache)) return Result::Success('', $cache);
1036+ $cache = $this->cache->get($cacheName);
1037+ if ($this->cache->validate($cache)) return Result::Success('', $cache);
10361038
10371039 $curl = $this->setupCurl("/dns/zones/{$domain}/records");
10381040 $res = $this->curlResult($curl);
10391041 if (isset($res->data['data'])) {
1040- $this->setCache($cacheName, $res->data);
1042+ $this->cache->set($cacheName, $res->data);
10411043 return Result::Success('', $res->data);
10421044 }
10431045
@@ -1060,8 +1062,8 @@
10601062 public function listEmails(array $query = []): Result {
10611063 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
10621064 $cacheName = 'listemails';
1063- $cache = $this->getCache($cacheName);
1064- if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
1065+ $cache = $this->cache->get($cacheName);
1066+ if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
10651067
10661068 foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
10671069 $uri = '/emails?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
@@ -1069,7 +1071,7 @@
10691071 $res = $this->curlResult($curl);
10701072 if (isset($res->data['data'])) {
10711073 $res->data['query'] = $query;
1072- $this->setCache($cacheName, $res->data);
1074+ $this->cache->set($cacheName, $res->data);
10731075 return Result::Success('', $res->data);
10741076 }
10751077
@@ -1090,7 +1092,7 @@
10901092 $curl = $this->setupCurl($uri, 'POST', $payload);
10911093 $res = $this->curlResult($curl);
10921094 if (isset($res->data['data'])) {
1093- $this->murderCache('listemails');
1095+ $this->cache->murder('listemails');
10941096 return Result::Success('メールテンプレートの追加に成功。', $res->data);
10951097 }
10961098
@@ -1112,7 +1114,7 @@
11121114 $curl = $this->setupCurl($uri, 'PUT', $payload);
11131115 $res = $this->curlResult($curl);
11141116 if (isset($res->data['data'])) {
1115- $this->murderCache('listemails');
1117+ $this->cache->murder('listemails');
11161118 if ($res->data['data']['success']) return Result::Success('メールテンプレートの更新に成功。', $res->data);
11171119 }
11181120
@@ -1133,7 +1135,7 @@
11331135 $curl = $this->setupCurl($uri, 'DELETE');
11341136 $res = $this->curlResult($curl);
11351137 if (isset($res->data['data'])) {
1136- $this->murderCache('listemails');
1138+ $this->cache->murder('listemails');
11371139 if ($res->data['data']['success']) return Result::Success('メールテンプレートの削除に成功。', $res->data);
11381140 }
11391141
@@ -1155,8 +1157,8 @@
11551157 public function listContacts(array $query = []): Result {
11561158 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
11571159 $cacheName = 'listcontacts';
1158- $cache = $this->getCache($cacheName);
1159- if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
1160+ $cache = $this->cache->get($cacheName);
1161+ if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
11601162
11611163 foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
11621164 $uri = '/contacts?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
@@ -1164,7 +1166,7 @@
11641166 $res = $this->curlResult($curl);
11651167 if (isset($res->data['data'])) {
11661168 $res->data['query'] = $query;
1167- $this->setCache($cacheName, $res->data);
1169+ $this->cache->set($cacheName, $res->data);
11681170 return Result::Success('', $res->data);
11691171 }
11701172
@@ -1184,7 +1186,7 @@
11841186 $curl = $this->setupCurl($uri, 'POST', $payload);
11851187 $res = $this->curlResult($curl);
11861188 if (isset($res)) {
1187- $this->murderCache('listcontacts');
1189+ $this->cache->murder('listcontacts');
11881190 return Result::Success('', $res->data);
11891191 }
11901192
@@ -1201,8 +1203,8 @@
12011203 public function getContact(int $id, bool $withAdditionalData = false): Result {
12021204 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
12031205 $cacheName = "getcontact-{$id}";
1204- $cache = $this->getCache($cacheName);
1205- if ($this->isValidLifespan($cache, $id, 'id')) return Result::Success('', $cache);
1206+ $cache = $this->cache->get($cacheName);
1207+ if ($this->cache->validate($cache, $id, 'id')) return Result::Success('', $cache);
12061208
12071209 $query = [ 'with_additional_data' => $withAdditionalData ? 'true' : 'false' ];
12081210 $uri = "/contacts/{$id}?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
@@ -1211,7 +1213,7 @@
12111213 $res = $this->curlResult($curl);
12121214 if (isset($res->data['data'])) {
12131215 $res->data['id'] = $id;
1214- $this->setCache($cacheName, $res->data);
1216+ $this->cache->set($cacheName, $res->data);
12151217 return Result::Success('', $res->data);
12161218 }
12171219
@@ -1233,8 +1235,8 @@
12331235 $curl = $this->setupCurl($uri, 'PUT', $payload);
12341236 $res = $this->curlResult($curl);
12351237 if (isset($res->data['data'])) {
1236- $this->murderCache("getcontact-{$id}");
1237- $this->murderCache('listcontacts');
1238+ $this->cache->murder("getcontact-{$id}");
1239+ $this->cache->murder('listcontacts');
12381240 if ($res->data['data']['success']) return Result::Success('連絡先の更新に成功。', $res->data);
12391241 }
12401242
@@ -1254,8 +1256,8 @@
12541256 $curl = $this->setupCurl($uri, 'DELETE');
12551257 $res = $this->curlResult($curl);
12561258 if (isset($res->data['data'])) {
1257- $this->murderCache("getcontact-{$id}");
1258- $this->murderCache('listcontacts');
1259+ $this->cache->murder("getcontact-{$id}");
1260+ $this->cache->murder('listcontacts');
12591261 if ($res->data['data']['success']) return Result::Success('連絡先の削除に成功。');
12601262 }
12611263
@@ -1273,8 +1275,8 @@
12731275 public function listCustomers(array $query = []): Result {
12741276 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
12751277 $cacheName = 'listcustomers';
1276- $cache = $this->getCache($cacheName);
1277- if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
1278+ $cache = $this->cache->get($cacheName);
1279+ if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
12781280
12791281 foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
12801282 $uri = '/customers?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
@@ -1282,7 +1284,7 @@
12821284 $res = $this->curlResult($curl);
12831285 if (isset($res->data['data'])) {
12841286 $res->data['query'] = $query;
1285- $this->setCache($cacheName, $res->data);
1287+ $this->cache->set($cacheName, $res->data);
12861288 return Result::Success('', $res->data);
12871289 }
12881290
@@ -1302,7 +1304,7 @@
13021304 $curl = $this->setupCurl($uri, 'POST', $payload);
13031305 $res = $this->curlResult($curl);
13041306 if (isset($res)) {
1305- $this->murderCache('listcustomers');
1307+ $this->cache->murder('listcustomers');
13061308 return Result::Success('', $res->data);
13071309 }
13081310
@@ -1319,8 +1321,8 @@
13191321 public function getCustomer(string $handle, bool $withAdditionalData = false): Result {
13201322 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
13211323 $cacheName = "getcustomer-{$handle}";
1322- $cache = $this->getCache($cacheName);
1323- if ($this->isValidLifespan($cache, $handle, 'handle')) return Result::Success('', $cache);
1324+ $cache = $this->cache->get($cacheName);
1325+ if ($this->cache->validate($cache, $handle, 'handle')) return Result::Success('', $cache);
13241326
13251327 $query = [ 'with_additional_data' => $withAdditionalData ? 'true' : 'false' ];
13261328 $uri = "/customers/{$handle}?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
@@ -1329,7 +1331,7 @@
13291331 $res = $this->curlResult($curl);
13301332 if (isset($res->data['data'])) {
13311333 $res->data['handle'] = $handle;
1332- $this->setCache($cacheName, $res->data);
1334+ $this->cache->set($cacheName, $res->data);
13331335 return Result::Success('', $res->data);
13341336 }
13351337
@@ -1351,7 +1353,8 @@
13511353 $curl = $this->setupCurl($uri, 'PUT', $payload);
13521354 $res = $this->curlResult($curl);
13531355 if (isset($res->data['data'])) {
1354- $this->murderCache('listcustomers');
1356+ $this->cache->murder('listcustomers');
1357+ $this->cache->murder("getcustomer-{$handle}");
13551358 if ($res->data['data']['success']) return Result::Success('顧客様の更新に成功。', $res->data);
13561359 }
13571360
@@ -1371,7 +1374,8 @@
13711374 $curl = $this->setupCurl($uri, 'DELETE');
13721375 $res = $this->curlResult($curl);
13731376 if (isset($res->data['data'])) {
1374- $this->murderCache('listcustomers');
1377+ $this->cache->murder('listcustomers');
1378+ $this->cache->murder("getcustomer-{$handle}");
13751379 if ($res->data['data']['success']) return Result::Success('顧客様の削除に成功。');
13761380 }
13771381
@@ -1390,8 +1394,8 @@
13901394 public function listEmailVerifications(array $query = []): Result {
13911395 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
13921396 $cacheName = 'listemailverifications';
1393- $cache = $this->getCache($cacheName);
1394- if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
1397+ $cache = $this->cache->get($cacheName);
1398+ if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
13951399
13961400 foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
13971401 $uri = '/customers/verifications/emails/domains?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
@@ -1399,7 +1403,7 @@
13991403 $res = $this->curlResult($curl);
14001404 if (isset($res->data['data'])) {
14011405 $res->data['query'] = $query;
1402- $this->setCache($cacheName, $res->data);
1406+ $this->cache->set($cacheName, $res->data);
14031407 return Result::Success('', $res->data);
14041408 }
14051409
@@ -1420,7 +1424,7 @@
14201424 $curl = $this->setupCurl($uri, 'POST', ['email' => $email, 'language' => $language, 'tag' => $tag]);
14211425 $res = $this->curlResult($curl);
14221426 if (isset($res->data['data'])) {
1423- $this->murderCache('listemailverifications');
1427+ $this->cache->murder('listemailverifications');
14241428 return Result::Success('メール認証の再起動に成功。', $res->data);
14251429 }
14261430
@@ -1444,7 +1448,7 @@
14441448 $curl = $this->setupCurl($uri, 'POST', ['email' => $email, 'handle' => $handle, 'language' => $language, 'tag' => $tag]);
14451449 $res = $this->curlResult($curl);
14461450 if (isset($res->data['data'])) {
1447- $this->murderCache('listemailverifications');
1451+ $this->cache->murder('listemailverifications');
14481452 return Result::Success('メール認証の起動に成功。', $res->data);
14491453 }
14501454
@@ -1463,8 +1467,8 @@
14631467 public function getReseller(array $query = []): Result {
14641468 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
14651469 $cacheName = 'getreseller';
1466- $cache = $this->getCache($cacheName);
1467- if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
1470+ $cache = $this->cache->get($cacheName);
1471+ if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
14681472
14691473 foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
14701474 $uri = '/resellers?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
@@ -1472,7 +1476,7 @@
14721476 $res = $this->curlResult($curl);
14731477 if (isset($res->data['data'])) {
14741478 $res->data['query'] = $query;
1475- $this->setCache($cacheName, $res->data);
1479+ $this->cache->set($cacheName, $res->data);
14761480 return Result::Success('', $res->data);
14771481 }
14781482
@@ -1494,7 +1498,7 @@
14941498 $curl = $this->setupCurl($uri, 'PUT', $payload);
14951499 $res = $this->curlResult($curl);
14961500 if (isset($res->data['data'])) {
1497- $this->murderCache('getreseller');
1501+ $this->cache->murder('getreseller');
14981502 if ($res->data['data']['success']) return Result::Success('リセラーの更新に成功。', $res->data);
14991503 }
15001504
@@ -1512,15 +1516,15 @@
15121516 public function listSettings(): Result {
15131517 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
15141518 $cacheName = 'listsettings';
1515- $cache = $this->getCache($cacheName);
1516- if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
1519+ $cache = $this->cache->get($cacheName);
1520+ if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
15171521
15181522 $uri = '/resellers/settings';
15191523 $curl = $this->setupCurl($uri);
15201524 $res = $this->curlResult($curl);
15211525 if (isset($res->data['data'])) {
15221526 $res->data['query'] = $query;
1523- $this->setCache($cacheName, $res->data);
1527+ $this->cache->set($cacheName, $res->data);
15241528 return Result::Success('', $res->data);
15251529 }
15261530
@@ -1538,15 +1542,15 @@
15381542 public function listStatistics(array $query = []): Result {
15391543 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
15401544 $cacheName = 'liststatistics';
1541- $cache = $this->getCache($cacheName);
1542- if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
1545+ $cache = $this->cache->get($cacheName);
1546+ if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
15431547
15441548 $uri = '/resellers/statistics';
15451549 $curl = $this->setupCurl($uri);
15461550 $res = $this->curlResult($curl);
15471551 if (isset($res->data['data'])) {
15481552 $res->data['query'] = $query;
1549- $this->setCache($cacheName, $res->data);
1553+ $this->cache->set($cacheName, $res->data);
15501554 return Result::Success('', $res->data);
15511555 }
15521556
@@ -1565,8 +1569,8 @@
15651569 public function listTags(array $query = []): Result {
15661570 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
15671571 $cacheName = 'listtags';
1568- $cache = $this->getCache($cacheName);
1569- if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
1572+ $cache = $this->cache->get($cacheName);
1573+ if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
15701574
15711575 foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
15721576 $uri = '/tags?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
@@ -1574,7 +1578,7 @@
15741578 $res = $this->curlResult($curl);
15751579 if (isset($res->data['data'])) {
15761580 $res->data['query'] = $query;
1577- $this->setCache($cacheName, $res->data);
1581+ $this->cache->set($cacheName, $res->data);
15781582 return Result::Success('', $res->data);
15791583 }
15801584
@@ -1595,7 +1599,7 @@
15951599 $curl = $this->setupCurl($uri, 'POST', $payload);
15961600 $res = $this->curlResult($curl);
15971601 if (isset($res->data['data'])) {
1598- $this->murderCache('listtags');
1602+ $this->cache->murder('listtags');
15991603 return Result::Success('タグの追加に成功。', $res->data);
16001604 }
16011605
@@ -1616,7 +1620,7 @@
16161620 $curl = $this->setupCurl($uri, 'DELETE', $payload);
16171621 $res = $this->curlResult($curl);
16181622 if (isset($res->data['data'])) {
1619- $this->murderCache('listtags');
1623+ $this->cache->murder('listtags');
16201624 if ($res->data['data']['success']) return Result::Success('タグの削除に成功。', $res->data);
16211625 }
16221626
@@ -1641,7 +1645,7 @@
16411645 $curl = $this->setupCurl($uri, 'POST', $payload);
16421646 $res = $this->curlResult($curl);
16431647 if (isset($res)) {
1644- $this->murderCache('listdomains');
1648+ $this->cache->murder('listdomains');
16451649 return Result::Success('', $res->data);
16461650 }
16471651
@@ -1659,8 +1663,8 @@
16591663 public function getSeDomain(string $domain, array $query = []): Result {
16601664 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
16611665 $cacheName = "getsedomain-{$domain}";
1662- $cache = $this->getCache($cacheName);
1663- if ($this->isValidLifespan($cache, $domain, 'domain')) return Result::Success('', $cache);
1666+ $cache = $this->cache->get($cacheName);
1667+ if ($this->cache->validate($cache, $domain, 'domain')) return Result::Success('', $cache);
16641668
16651669 $uri = "/spam-expert/domains/{$domain}?".http_build_query($query, '', '&', PHP_QUERY_RFC3986);
16661670 // kys($uri);
@@ -1668,7 +1672,7 @@
16681672 $res = $this->curlResult($curl);
16691673 if (isset($res->data['data'])) {
16701674 $res->data['domain'] = $domain;
1671- $this->setCache($cacheName, $res->data);
1675+ $this->cache->set($cacheName, $res->data);
16721676 return Result::Success('', $res->data);
16731677 }
16741678
@@ -1690,8 +1694,8 @@
16901694 $curl = $this->setupCurl($uri, 'PUT', $payload);
16911695 $res = $this->curlResult($curl);
16921696 if (isset($res->data['data'])) {
1693- $this->murderCache('listdomains');
1694- $this->murderCache("getsedomain-{$domain}");
1697+ $this->cache->murder('listdomains');
1698+ $this->cache->murder("getsedomain-{$domain}");
16951699 if ($res->data['data']['success']) return Result::Success('SEDomainの更新に成功。', $res->data);
16961700 }
16971701
@@ -1712,8 +1716,8 @@
17121716 $curl = $this->setupCurl($uri, 'DELETE');
17131717 $res = $this->curlResult($curl);
17141718 if (isset($res->data['data'])) {
1715- $this->murderCache('listdomains');
1716- $this->murderCache("getsedomain-{$domain}");
1719+ $this->cache->murder('listdomains');
1720+ $this->cache->murder("getsedomain-{$domain}");
17171721 if ($res->data['data']['success']) return Result::Success('SEDomainの削除に成功。');
17181722 }
17191723
@@ -1734,8 +1738,8 @@
17341738 public function listApproverEmails(array $query = []): Result {
17351739 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
17361740 $cacheName = 'listapproveremails';
1737- $cache = $this->getCache($cacheName);
1738- if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
1741+ $cache = $this->cache->get($cacheName);
1742+ if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
17391743
17401744 foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
17411745 $uri = '/ssl/approver-emails?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
@@ -1743,7 +1747,7 @@
17431747 $res = $this->curlResult($curl);
17441748 if (isset($res->data['data'])) {
17451749 $res->data['query'] = $query;
1746- $this->setCache($cacheName, $res->data);
1750+ $this->cache->set($cacheName, $res->data);
17471751 return Result::Success('', $res->data);
17481752 }
17491753
@@ -1811,7 +1815,7 @@
18111815 $curl = $this->setupCurl($uri, 'PUT', ['id' => $id, 'approver_email' => $approverEmail]);
18121816 $res = $this->curlResult($curl);
18131817 if (isset($res)) {
1814- $this->murderCache('listapproveremails');
1818+ $this->cache->murder('listapproveremails');
18151819 return Result::Success('', $res->data);
18161820 }
18171821
@@ -1832,7 +1836,7 @@
18321836 $curl = $this->setupCurl($uri, 'POST', ['id' => $id]);
18331837 $res = $this->curlResult($curl);
18341838 if (isset($res)) {
1835- $this->murderCache('listapproveremails');
1839+ $this->cache->murder('listapproveremails');
18361840 return Result::Success('', $res->data);
18371841 }
18381842
@@ -1873,8 +1877,8 @@
18731877 public function listSslProducts(array $query = []): Result {
18741878 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
18751879 $cacheName = 'listsslproducts';
1876- $cache = $this->getCache($cacheName);
1877- if ($this->isValidLifespan($cache, $query)) return Result::Success('', $cache);
1880+ $cache = $this->cache->get($cacheName);
1881+ if ($this->cache->validate($cache, $query)) return Result::Success('', $cache);
18781882
18791883 foreach ($query as $k => $v) { if (is_bool($v)) $query[$k] = $v ? 'true' : 'false'; }
18801884 $uri = '/ssl/products?'.http_build_query($query, '', '&', PHP_QUERY_RFC3986);
@@ -1882,7 +1886,7 @@
18821886 $res = $this->curlResult($curl);
18831887 if (isset($res->data['data'])) {
18841888 $res->data['query'] = $query;
1885- $this->setCache($cacheName, $res->data);
1889+ $this->cache->set($cacheName, $res->data);
18861890 return Result::Success('', $res->data);
18871891 }
18881892
@@ -1899,14 +1903,14 @@
18991903 public function getSslProduct(int $id): Result {
19001904 if (!OPENPROVIDER_ENABLED) return Result::error('エラー:OpenProviderは無効です。');
19011905 $cacheName = "getsslproduct-{$id}";
1902- $cache = $this->getCache($cacheName);
1903- if ($this->isValidLifespan($cache, $id, 'id')) return Result::Success('', $cache);
1906+ $cache = $this->cache->get($cacheName);
1907+ if ($this->cache->validate($cache, $id, 'id')) return Result::Success('', $cache);
19041908 // kys($uri);
19051909 $curl = $this->setupCurl($uri);
19061910 $res = $this->curlResult($curl);
19071911 if (isset($res->data['data'])) {
19081912 $res->data['id'] = $id;
1909- $this->setCache($cacheName, $res->data);
1913+ $this->cache->set($cacheName, $res->data);
19101914 return Result::Success('', $res->data);
19111915 }
19121916
@@ -1967,76 +1971,5 @@
19671971 assert_not_null($body, "返事ボディーは空です。");
19681972
19691973 return Result::Success('', json_decode($body, true));
1970- }
1971-
1972- /**
1973- * キャッシュの作成
1974- *
1975- * @param string $type キャッシュ類(例:login、domainlist等)
1976- * @param array $data 保存するデータ
1977- * @return Result
1978- */
1979- private function setCache(string $type, array $data): Result {
1980- if (!file_exists($this->dataDir)) {
1981- if (!mkdir($this->dataDir, 0755))
1982- return Result::Error('エラー:ユーザーのアイコンディレクトリの作成に失敗。');
1983- }
1984-
1985- $data['lifespan'] = time();
1986- $json = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
1987- if (file_put_contents("{$this->dataDir}{$type}.json", $json) === false) return Result::Error('エラー:ユーザーデータの保存に失敗。');
1988-
1989- return Result::Success();
1990- }
1991-
1992- /**
1993- * キャッシュから受け取り
1994- *
1995- * @param string $type キャッシュ類(例:login、domainlist等)
1996- * @return array
1997- */
1998- private function getCache(string $type): array {
1999- if (!file_exists("{$this->dataDir}{$type}.json")) return [];
2000-
2001- $content = file_get_contents("{$this->dataDir}{$type}.json");
2002- if ($content === false) return [];
2003-
2004- $data = json_decode($content, true);
2005- if (json_last_error() !== JSON_ERROR_NONE || !is_array($data)) return [];
2006-
2007- if ($type === 'login') {
2008- $this->token = $data['data']['token'];
2009- $this->lastAuth = $data['last_auth'];
2010- }
2011-
2012- return $data;
2013- }
2014-
2015- /**
2016- * キャッシュを破壊する
2017- *
2018- * @param string $name キャッシュのファイル名
2019- * @return Result
2020- */
2021- private function murderCache(string $name): Result {
2022- if (!file_exists("{$this->dataDir}{$name}.json")) return Result::Error('キャッシュファイルが存在しない。');
2023- if (!unlink("{$this->dataDir}{$name}.json")) return Result::Error('キャッシュファイルの削除に失敗。');
2024- return Result::Success();
2025- }
2026-
2027- /**
2028- * キャッシュ有効期限の確認
2029- *
2030- * @param array $cache
2031- * @param mixed $data デフォルト=null
2032- * @param string $dataPoint デフォルト=query
2033- * @return bool
2034- */
2035- private function isValidLifespan(array $cache, mixed $data = null, string $dataPoint = 'query'): bool {
2036- if (NULL === $data) return (!empty($cache) && (isset($cache['lifespan']) && time() < ($cache['lifespan'] + $this->dataDuration)));
2037- else return (!empty($cache)
2038- && (isset($cache[$dataPoint])
2039- && $cache[$dataPoint] === $data)
2040- && (isset($cache['lifespan']) && time() < ($cache['lifespan'] + $this->dataDuration)));
20411974 }
20421975 }
@@ -108,5 +108,4 @@
108108 <button>送信</button>
109109 </form>
110110 </p>
111- {@ kys($data) @}
112111 {@ include(common/footer) @}
@@ -1,5 +1,5 @@
11 {@ include(common/header) @}
2- <a href="/openprovider/createcustomer">顧客様の追加</a><br />
2+ <a href="/openprovider/createcustomer" class="op-button-create">顧客様の追加</a><br />
33 検索<br />
44 {@ if (isset($data['data']['results'])) @}
55 <table>