summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHorus2016-07-03 21:17:34 +0200
committerHorus2016-07-03 21:17:34 +0200
commitf95af4211bc24e5cf0b5b017c7d50113e4000968 (patch)
tree30c97d3dd2cbb99bfefa458dab27434a557f2611
parentf5cf66b6929928fe5a4a6cf227f9a2f2195329e5 (diff)
downloadimap2rss-f95af4211bc24e5cf0b5b017c7d50113e4000968.tar.gz
Add caching.
-rw-r--r--composer.json3
-rw-r--r--composer.lock54
-rw-r--r--imap.php1
-rw-r--r--index.php21
4 files changed, 73 insertions, 6 deletions
diff --git a/composer.json b/composer.json
index bd337c6..b700895 100644
--- a/composer.json
+++ b/composer.json
@@ -1,6 +1,7 @@
{
"require": {
"php-imap/php-imap": "^2.0",
- "suin/php-rss-writer": "^1.4"
+ "suin/php-rss-writer": "^1.4",
+ "predis/predis": "^1.1"
}
}
diff --git a/composer.lock b/composer.lock
index 91d9352..5412ff7 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "hash": "ceef96fe5f0bf30814febdce51afaaf4",
- "content-hash": "5e9081cc591450aaf17d67806d687c74",
+ "hash": "73069b5929aaf8a36d0999e3862b423d",
+ "content-hash": "2afaee71251c82c35a7e96e2e0e712a5",
"packages": [
{
"name": "php-imap/php-imap",
@@ -52,6 +52,56 @@
"time": "2015-12-14 02:46:12"
},
{
+ "name": "predis/predis",
+ "version": "v1.1.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/nrk/predis.git",
+ "reference": "f0210e38881631afeafb56ab43405a92cafd9fd1"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/nrk/predis/zipball/f0210e38881631afeafb56ab43405a92cafd9fd1",
+ "reference": "f0210e38881631afeafb56ab43405a92cafd9fd1",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.9"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.8"
+ },
+ "suggest": {
+ "ext-curl": "Allows access to Webdis when paired with phpiredis",
+ "ext-phpiredis": "Allows faster serialization and deserialization of the Redis protocol"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "Predis\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Daniele Alessandri",
+ "email": "suppakilla@gmail.com",
+ "homepage": "http://clorophilla.net"
+ }
+ ],
+ "description": "Flexible and feature-complete Redis client for PHP and HHVM",
+ "homepage": "http://github.com/nrk/predis",
+ "keywords": [
+ "nosql",
+ "predis",
+ "redis"
+ ],
+ "time": "2016-06-16 16:22:20"
+ },
+ {
"name": "suin/php-rss-writer",
"version": "1.4.0",
"source": {
diff --git a/imap.php b/imap.php
index 191447c..01d8dae 100644
--- a/imap.php
+++ b/imap.php
@@ -18,6 +18,7 @@ function getMail($user, $pass, $inbox, $max_items){
}
} catch( Exception $e ) {
header( $_SERVER["SERVER_PROTOCOL"] . " 403 Forbidden" );
+ error_log($e->getMessage());
exit(1);
}
diff --git a/index.php b/index.php
index b40b8e1..3daeb7e 100644
--- a/index.php
+++ b/index.php
@@ -1,11 +1,26 @@
<?php
+require_once __DIR__ . '/bootstrap.php';
+
$user = "feed@maxmail.xyz";
-$pass = "1234";
-$inbox = array("INBOX", "Trash");
+$pass = "1234abc";
+#$inbox = array("INBOX", "Trash");
+$inbox = array("INBOX");
$max_items = 10;
+$ttl = 60*60;
$mail = getMail($user, $pass, $inbox, $max_items);
$inbox_string = implode(",", $inbox);
-$feed = generate_feed($mail, $user, $inbox_string);
+$cache_key = md5($user . $inbox_string);
+$client = new Predis\Client('tcp://127.0.0.1:6379?database=2');
+
+$feed = $client->get('feed_' . $cache_key);
+if ( false !== $feed ) {
+ $feed = generate_feed($mail, $user, $inbox_string);
+ $client->set('feed_' . $cache_key, $feed);
+ $client->expire('feed_' . $cache_key, $ttl);
+}
+
+header("Content-type: application/rss+xml");
+echo $feed;