https://github.com/dude920228/php-cache
Cache implementation for php
https://github.com/dude920228/php-cache
caching caching-library php php-cache sockets
Last synced: 28 days ago
JSON representation
Cache implementation for php
- Host: GitHub
- URL: https://github.com/dude920228/php-cache
- Owner: dude920228
- License: gpl-3.0
- Created: 2018-05-30T14:28:49.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-07-11T08:42:38.000Z (over 3 years ago)
- Last Synced: 2025-07-22T13:52:15.216Z (6 months ago)
- Topics: caching, caching-library, php, php-cache, sockets
- Language: PHP
- Size: 1.78 MB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.styleci.io/repos/135454839) [](https://scrutinizer-ci.com/g/dude920228/php-cache/?branch=master) [](https://scrutinizer-ci.com/g/dude920228/php-cache/build-status/master)
# php-cache
Cache implementation for php
# Usage:
#### Prequests:
- PHP 7.2
- composer
#### Installing via composer:
```
composer require kdudas/php-cache
```
#### Supperted data types:
- String
- Integer/Float/Double
- Array
- Objects
#### Creating a new server instance
```
addConfig($config);
$serviceManager = new ServiceManager($configAggregator->getMergedConfig());
$server = $serviceManager->get(CacheServer::class);
$server->run();
```
#### Running the server:
```
php testServer.php
```
#### OR
```
mv daemon.sh /etc/init.d/php-cache
chmod +x /etc/init.d/php-cache
# now you can use systemctl style service management
sudo service php-cache start
```
##### Note: you can modify the contents of `daemon.sh` if you want to use other directories
#### Configuration array:
- `config`: Basic configuration array
-- `memoryLimit`: as the name suggests, after we exceed the limit, our data in the cache pool gets backed up to file system
-- `location`: server IP address or socket file location (string)
-- `port`: the port to run the sockets on (number)
-- `bufferSize`: how big chunks of data is being read from a stream (bytes)
-- `ttl`: time to live; how long an entry should take space up in the cache pool before being deleted (seconds)
-- `backupTime`: schedule backups (seconds)
-- `backupDir`: where to store backed up data? A backup is made when we are shutting down the server service, when the scheduled backup occures or our cache pool exceeded it's memory limit
-- `socketType`: which socket type should we use? Open a port on the network for the socket or create a file for the socket. Values must be either `file` (`CacheIOHandler::SOCKET_TYPE_FILE`) or `ip` (`CacheIOHandler::SOCKET_TYPE_IP`)
- `services`: service manager configuration
-- `aliases`: a name assigned for a real service (Example: `'cache-server' => CacheServer::class`)
-- `factories`: service name with factory name for service pairs
-- `invokables`: services with no dependencies
#### Creating a new client instance
```
get(CacheClient::class);
$client->set('test', 'ASD');
echo $client->get('test');
```
##### You can run the client either from browser or console
```
php testClient.php
```
#### CLI Commands:
`./phpCache get ` gets entries for the specified key. If no key is specified, it returns all entries.
`./phpCache set ` pushes an entry to the cache pool with the given key - value pair.
`./phpCache delete ` deletes the entry with the given key