1 package org.apache.commons.jcs.auxiliary.disk.block;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import org.apache.commons.jcs.auxiliary.disk.AbstractDiskCacheAttributes;
23
24 /**
25 * This holds attributes for Block Disk Cache configuration.
26 * <p>
27 * @author Aaron Smuts
28 */
29 public class BlockDiskCacheAttributes
30 extends AbstractDiskCacheAttributes
31 {
32 /** Don't change */
33 private static final long serialVersionUID = 6568840097657265989L;
34
35 /** The size per block in bytes. */
36 private int blockSizeBytes;
37
38 /** Maximum number of keys to be kept in memory */
39 private static final int DEFAULT_MAX_KEY_SIZE = 5000;
40
41 /** -1 means no limit. */
42 private int maxKeySize = DEFAULT_MAX_KEY_SIZE;
43
44 /** How often should we persist the keys. */
45 private static final long DEFAULT_KEY_PERSISTENCE_INTERVAL_SECONDS = 5 * 60;
46
47 /** The keys will be persisted at this interval. -1 mean never. */
48 private long keyPersistenceIntervalSeconds = DEFAULT_KEY_PERSISTENCE_INTERVAL_SECONDS;
49
50 /**
51 * The size of the blocks. All blocks are the same size.
52 * <p>
53 * @param blockSizeBytes The blockSizeBytes to set.
54 */
55 public void setBlockSizeBytes( int blockSizeBytes )
56 {
57 this.blockSizeBytes = blockSizeBytes;
58 }
59
60 /**
61 * @return Returns the blockSizeBytes.
62 */
63 public int getBlockSizeBytes()
64 {
65 return blockSizeBytes;
66 }
67
68 /**
69 * @param maxKeySize The maxKeySize to set.
70 */
71 public void setMaxKeySize( int maxKeySize )
72 {
73 this.maxKeySize = maxKeySize;
74 }
75
76 /**
77 * @return Returns the maxKeySize.
78 */
79 public int getMaxKeySize()
80 {
81 return maxKeySize;
82 }
83
84 /**
85 * @param keyPersistenceIntervalSeconds The keyPersistenceIntervalSeconds to set.
86 */
87 public void setKeyPersistenceIntervalSeconds( long keyPersistenceIntervalSeconds )
88 {
89 this.keyPersistenceIntervalSeconds = keyPersistenceIntervalSeconds;
90 }
91
92 /**
93 * @return Returns the keyPersistenceIntervalSeconds.
94 */
95 public long getKeyPersistenceIntervalSeconds()
96 {
97 return keyPersistenceIntervalSeconds;
98 }
99
100 /**
101 * Write out the values for debugging purposes.
102 * <p>
103 * @return String
104 */
105 @Override
106 public String toString()
107 {
108 StringBuilder str = new StringBuilder();
109 str.append( "\nBlockDiskAttributes " );
110 str.append( "\n DiskPath [" + this.getDiskPath() + "]" );
111 str.append( "\n MaxKeySize [" + this.getMaxKeySize() + "]" );
112 str.append( "\n MaxPurgatorySize [" + this.getMaxPurgatorySize() + "]" );
113 str.append( "\n BlockSizeBytes [" + this.getBlockSizeBytes() + "]" );
114 str.append( "\n KeyPersistenceIntervalSeconds [" + this.getKeyPersistenceIntervalSeconds() + "]" );
115 str.append( "\n DiskLimitType [" + this.getDiskLimitType() + "]" );
116 return str.toString();
117 }
118 }