aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Lib/ObjCache.php
blob: 618522cf24681739781dc26581c256c7a121bfd3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php

namespace Zotlabs\Lib;

class ObjCache
{
	public static function Get($path, $type = 'as')
	{
		if (!$path) {
			return [];
		}

		$localpath = Hashpath::path($path, 'store/[data]/[obj]/' . $type, 2, alg: 'sha256');
		if (file_exists($localpath)) {
			return unserialise(file_get_contents($localpath));
		}

		return [];
	}

	public static function Set($path, $content, $type = 'as') {
		if (!$path) {
			return;
		}

		$localpath = Hashpath::path($path, 'store/[data]/[obj]/' . $type, 2, alg: 'sha256');
		file_put_contents($localpath, serialise($content));
	}

	public static function Delete($path, $type = 'as') {
		if (!$path) {
			return;
		}

		$localpath = Hashpath::path($path, 'store/[data]/[obj]/' . $type, 2, alg: 'sha256');
		if (file_exists($localpath)) {
			unlink($localpath);
		}
	}
}